- From: Joshua Bell <notifications@github.com>
- Date: Thu, 05 Jan 2017 19:34:31 -0800
- To: w3c/IndexedDB <IndexedDB@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/IndexedDB/pull/133/review/15437640@github.com>
inexorabletash commented on this pull request. > +other tabs, you should use the "versionchange" event to close the connection to +the database. + +<pre class=lang-javascript> +db.onversionchange = function() { + // First, save any unsaved data: + saveUnsavedData().then(function() { + // Now you need to close the database. + // If the document isn't being actively used, it may be appropriate to reload: + if (!document.hasFocus()) { + location.reload(); + // Reloading will close the database, and also reload with the new JavaScript + // and database definitions. + } else { + // Alternatively you may close the database and display a message to the + // user. You need to ensure this isn't a disruptive user experience. The open request trying to do the upgrade gets "blocked" if there are any other connections that don't close as soon as they receive "versionchange". So one approach might be: ```js const open = indexedDB.open(name, version); open.onerror = e => notify(`Something went wrong: ${e.message}`); open.onblocked = e => notify('Close the other tabs and then click OK'); open.onupgradeneeded = e => { if (e.oldVersion === 0) { ... } if (e.oldVersion === 1) { ... } ... }; open.onsuccess = e => { const db = open.result; db.onversionchange = e => notify('Another tab wants to upgrade. Close this one.'); }; ``` -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/w3c/IndexedDB/pull/133
Received on Friday, 6 January 2017 03:35:10 UTC