jakearchibald / idb

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

idb does not detect changes #292

Closed Dan178A closed 1 year ago

Dan178A commented 1 year ago

idb does not detect that the array of objectstores has one more element and continues to run long :
i.e. if there has been a change, it does not detect anything and continues as if nothing has happened.

const objectStores = [
                'refcom_1A_2017',
                'refcom_1A_2018',
                'refcom_1A_2019',
                'refcom_1A_2021',
                'refcom_1A_2022',
                'refcom_1B_2017',
                'refcom_1B_2018',
                'refcom_1B_2019'
            ];

const idb = await openDB('Refcomn', 1, {
  async upgrade(db, oldVersion, newVersion, transaction) {
    console.log(oldVersion)
    console.log(newVersion)
    const objectStoreNames = Array.from(db.objectStoreNames);
    for (const keyName of objectStoreNames) {
      if (!objectStores.includes(keyName)) {
        console.log(`Deleting object store ${keyName}`);
        if (transaction && transaction.objectStore(keyName)) {
          await transaction.objectStore(keyName).clear();
        }
        await db.deleteObjectStore(keyName);
      }
    }

    for (const keyName of objectStores) {
      if (!objectStoreNames.includes(keyName)) {
        console.log(`Creating object store ${keyName}`);
        db.createObjectStore(keyName);
      }
    }
  },
  blocked() {
    console.log('This page is blocked by another open connection. Please close all tabs!');
  }
});
jakearchibald commented 1 year ago

I don't understand this report.

Which change are you trying to detect? What does "continues to run long" mean? How does objectstores gain "one more element", and what is this element?