From fd43dc6e5deae4006aea581f44dba61ccf720f81 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Wed, 5 Sep 2018 19:52:51 -0700 Subject: [PATCH] fix idb getall in edge (#535) * fix idb getall in edge fixes #532 * try to fix * this should work * fixup --- routes/_database/databaseLifecycle.js | 25 +++++++++++++++---------- routes/_utils/asyncModules.js | 4 ---- routes/_utils/loadPolyfills.js | 2 -- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/routes/_database/databaseLifecycle.js b/routes/_database/databaseLifecycle.js index 4c75d1c..011273d 100644 --- a/routes/_database/databaseLifecycle.js +++ b/routes/_database/databaseLifecycle.js @@ -22,15 +22,12 @@ const DB_VERSION_INITIAL = 9 const DB_VERSION_SEARCH_ACCOUNTS = 10 const DB_VERSION_CURRENT = 10 -export function getDatabase (instanceName) { - if (!instanceName) { - throw new Error('instanceName is undefined in getDatabase()') - } - if (databaseCache[instanceName]) { - return Promise.resolve(databaseCache[instanceName]) - } +if (process.browser) { + require('indexeddb-getall-shim') // needed for Edge +} - databaseCache[instanceName] = new Promise((resolve, reject) => { +function createDatabase (instanceName) { + return new Promise((resolve, reject) => { let req = indexedDB.open(instanceName, DB_VERSION_CURRENT) openReqs[instanceName] = req req.onerror = reject @@ -87,9 +84,17 @@ export function getDatabase (instanceName) { } } req.onsuccess = () => resolve(req.result) - }).then(res => { - return addKnownInstance(instanceName).then(() => res) }) +} + +export async function getDatabase (instanceName) { + if (!instanceName) { + throw new Error('instanceName is undefined in getDatabase()') + } + if (!databaseCache[instanceName]) { + databaseCache[instanceName] = await createDatabase(instanceName) + await addKnownInstance(instanceName) + } return databaseCache[instanceName] } diff --git a/routes/_utils/asyncModules.js b/routes/_utils/asyncModules.js index 3cbed92..c3c5b67 100644 --- a/routes/_utils/asyncModules.js +++ b/routes/_utils/asyncModules.js @@ -10,10 +10,6 @@ export const importRequestIdleCallback = () => import( /* webpackChunkName: 'requestidlecallback' */ 'requestidlecallback' ) -export const importIndexedDBGetAllShim = () => import( - /* webpackChunkName: 'indexeddb-getall-shim' */ 'indexeddb-getall-shim' - ) - export const importWebAnimationPolyfill = () => import( /* webpackChunkName: 'web-animations-js' */ 'web-animations-js' ) diff --git a/routes/_utils/loadPolyfills.js b/routes/_utils/loadPolyfills.js index 9642c9d..7f5a037 100644 --- a/routes/_utils/loadPolyfills.js +++ b/routes/_utils/loadPolyfills.js @@ -1,7 +1,6 @@ import { importIntersectionObserver, importRequestIdleCallback, - importIndexedDBGetAllShim, importWebAnimationPolyfill } from './asyncModules' @@ -9,7 +8,6 @@ export function loadPolyfills () { return Promise.all([ typeof IntersectionObserver === 'undefined' && importIntersectionObserver(), typeof requestIdleCallback === 'undefined' && importRequestIdleCallback(), - !IDBObjectStore.prototype.getAll && importIndexedDBGetAllShim(), !Element.prototype.animate && importWebAnimationPolyfill() ]) }