10000 forum users celebration - special event

Yeah, XD.

I’m working it out, I think my method might not be possible (thank goodness I’m question banned - MAN I thought I’d never say that)

I’m too lazy to read the code again, is this a library for in-browser database?

Yeah. Got it!

Code:

const { indexedDB } = globalThis;
const awaitEvent = (obj, handlerName, rejOnError = true, timeout = Infinity, callback = () => {}) => {
    if("object" !== typeof obj){
        throw new TypeError(`Argument provided for object to bind the listener to is not of type "object".`);
    }
    if("string" !== typeof handlerName){
        throw new TypeError(`Argument provided for object's event listener name is not of type "string".`);
    }
    if("function" !== typeof obj.addEventListener){
        throw new TypeError(`Object does not have an "addEventListener" function.`);
    }
    if("function" !== typeof callback){
        throw new TypeError(`Callback provided is not a function.`);
    }
    /*Status codes:
        0: ok
        1: timed out
    */
    return new Promise((res, rej) => {
       obj.addEventListener(handlerName, evt => {
           callback(evt);
            res({
                "ok": true,
                "status": 0,
                "statusText": ""
            });
       });
       if(timeout !== Infinity && timeout > 0){
           globalThis.setTimeout(timeout, () => {
               if(rejOnError){
                   rej({
                       "ok": false,
                       "status": 1,
                       "statusText": ""
                   });
               }
               else{
                   res({
                       "ok": false,
                       "status": 1,
                       "statusText": ""
                   });
               }
           });
       }
    });
};

const transactions = class {
    constructor() {
        this.db = null;
    }
    connect(name, version, upgradeNeededCallback = () => {}) {
        if(this.db !== null){
            throw new Error(`Database is already open. Close it using "disconnect()".`);
        }
        if("string" !== typeof name){
            throw new TypeError(`Argument provided for the database name is not of type "string".`);
        }
        if("number" !== typeof version){
            throw new TypeError(`Argument provided for the version is not of type "number".`);
        }
        if(version < 1){
            throw new TypeError(`Database version cannot be less than one. Expected a greater-than 0 value, got a less-than 0 value of ${version} instead.`);
        }
        if("function" !== typeof upgradeNeededCallback){
            throw new TypeError(`Argument provided for the upgrade needed callback is not a function.`);
        }
        return new Promise(async (res, rej) => {
            const dEntries = await indexedDB.databases();
            if(dEntries.filter(dEntry => dEntry.name === name).length < 1){
                rej(new Error(`Database is not initialized. Use "create()" instead.`));
                return;
            }
            const req = indexedDB.open(name, version);
            req.addEventListener("success", () => {
                this.db = req.result;
                res(this.db);
            });
            req.addEventListener("upgradeneeded", event => {
                this.db = req.result;
                upgradeNeededCallback(event, this.db);
                res(this.db);
            });
            req.addEventListener("error", err => rej(err));
        });
    }
    create(name, createdCallback = () => {}) {
        if(this.db !== null){
            throw new Error(`Database is already open. Close it using "disconnect()".`);
        }
        if("string" !== typeof name){
            throw new TypeError(`Argument provided for database name is not of type "string".`);
        }
        if("function" !== typeof createdCallback){
            throw new TypeError(`Argument provided for the initial creation callback is not a function.`);
        }
        return new Promise((res, rej) => {
            const req = indexedDB.open(name, 1);
            req.addEventListener("success", () => {
                rej(new Error(`Database is already created.`));
            });
            req.addEventListener("upgradeneeded", event => {
                if(event.oldVersion < 1){
                    this.db = req.result;
                    createdCallback(event, this.db);
                    res(this.db);
                }
                else{
                    rej(new Error(`Database is already created.`));
                }
            });
            req.addEventListener("error", err => rej(err));
        });
    }
    createObjectStore(name, options = {}){
        if(this.db === null){
            throw new Error(`Database is already open. Close it using "disconnect()".`);
        }
        if("string" !== typeof name){
            throw new TypeError(`Argument provided as the object store name is not of type "string".`);
        }
        if("object" !== typeof options){
            throw new TypeError(`Argument provided as the object store options is not of type "object".`);
        }
        return new Promise(async (res, rej) => {
            this.db.close();
            const dEntries = await indexedDB.databases();
            if(dEntries.filter(dEntry => dEntry.name === this.db.name).length < 1){
                rej(new Error(`Database is not initialized. Use "create()" instead.`));
                return;
            }
            //TODO & FIXME: Infinite update wait time (I'm probably upgrading it wrong)!!!
            const req = indexedDB.open(this.db.name, this.db.version + 1);
            req.addEventListener("upgradeneeded", event => {
                this.db = req.result;
                this.db.createObjectStore(name, options);
                console.log(this.db);
            });
            req.addEventListener("success", () => {
                this.db = req.result;
                this.db.addEventListener("versionchange", () => {
                    this.db.createObjectStore(name, options);
                    console.log(req);
                    res(this.db);
                });
            });
            console.log(req);
            req.addEventListener("error", err => rej(err));
            req.addEventListener("blocked", err => rej(err));
        });
    }
    disconnect() {
        this.db = null;
    }
};

export default transactions;

I wish we had executable code blocks like SO does :confused:

I’m making my own transaction handler because it’s hard to do indexedDB so I’ll use this for handling DB stuff (I’m using functions for their real purpose: to reduce code redundancies).

I found out the prob from here:

Reading does help! Who knew…

1 Like

OMG I found the best song, but it’s not out yet (I have Monstercat gold so I can listen early). I’ll show u when you can view it, it’s amazing.

Rich boy >:(

Its legit $60 a year (now $80 but whatever).

I’m actually poor.

Ok, I have $700 saved for a computer, but like it’s a dead effort at this point since parents are saying no.

Oh, and btw…

Are you celebrating Easter?

We are (kinda).

I… legit… slept… through… church!

And not “sleep in”, I actually was asleep.

They were talking about (according to my Mom) how God can bring everything back to life.

Duh, he’s God!!!

But I think the more amazing thing is that he chooses to bring things back to life :slight_smile:

As a muslim, not really.

1 Like

Ah…

At least we believe in the same God (with separate qualities, but whatever).

I was going to ask if u were Muslim (since a lot of people in your area probably are, but I don’t want to discriminate or be biased or stereotypical)…

Muslim/Jewish/Christians believe in the same God, practically - more evidence that he exists :slight_smile:

1 Like

Honestly I don’t mind whatever someone is Atheists or believes in god, as long as they don’t spread hate or don’t force me to believe in their beliefs. :smile:

1 Like

Yeah, I am a science enthusiast, but some things just don’t add up.

In fact!

According to the copenhagen interpretation (quantum mechanics, nvm), there must have been an intelligent observer before the creation of the universe.

But, there are flaws to interpretation… :frowning:

I personally prefer not to go with religions (especially my religion)
Let’s say, my religion is putting weird laws which i don’t agree with some of them. I go by what my wisdom says.

3 Likes

Yeah.

Anyways, my cat is like a factory input.

You put him in my brothers bed in one way and he goes out another exit.

Input… output!

Input… output!

1 Like

My cat is an escapist - he tried to get outside!

1 Like

He is the animal version of me

1 Like

Yeah, we all want to get away from something.

2 Likes

Yay, got the MD working!

Tomorrow (after school in person - uggh I have to go to hybrid :angry:), I’ll actually make a save feature :smiley:

Oh yeah, btw… I might want to expunge special chars in the title, otherwise they have to look up stuff like this%20that and it’s just inconvenient.

Oh wait… I have a tutorial list page… nvm XD

Still tho… maybe :confused:

2 Likes

The code looks great, too!

(Excuse the bad indenting, I copy-pasted it)

@anon19508339 Breathe - Monstercat

It’s out now, and it’s amazing!

Btw, I have to go to hybrid, wish me luck :sob:!

Unfortunately @system won’t let me create another reply (understandable).

Goodluck!

he? what if the god is female :slight_smile:

There is one thing in your sentence which could be translated like this :
“the more there are those who believe = proof that something exists”

If something is proven to exist then it is called an exact science.
If there is no evidence then you can only believe.

Which means believing in something can only be done if there is no evidence (especially without proof)
otherwise, for something for which there is evidence, belief makes no sense because it would not be called belief (it would be called a fact).

In short, these two concepts cannot go together.

The worst is when someone is convinced that his belief is the ultimate truth (because he doesn’t understand what I said above)
and then that his belief that something is true is the cause of many wars.

Dogma should be avoided and always reconsider everything (open mind).

5 Likes

I remember someone using “she” for satan lol (it was on Deviantart if I remember correctly)

My country, lol.

2 Likes