jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.29k stars 353 forks source link

openDB's terminated callback is not firing #169

Closed bgerm closed 4 years ago

bgerm commented 4 years ago

Expected:
terminated to be called when an IndexedDB database is manually deleted (with terminated configured)

Result: terminated does not get called.

It appears close is being set up as an addEventListener for the IDBOpenDBRequest object, but the docs show this fires for the IDBDatabase object.

I think the change should be something like:

if (terminated || blocking)
    openPromise
        .then(db => {
            if (terminated)
              db.addEventListener('close', terminated)
            if (blocking)
              db.addEventListener('versionchange', blocking)
        })
        .catch(() => { });

Current:

if (terminated)
    request.addEventListener('close', () => terminated());
if (blocking) {
    openPromise
        .then(db => db.addEventListener('versionchange', blocking))
        .catch(() => { });
}

Thanks for this library.

jakearchibald commented 4 years ago

Published as 5.0.2. Thanks for spotting this!