fix idb getall in edge (#535)
* fix idb getall in edge fixes #532 * try to fix * this should work * fixup
This commit is contained in:
parent
334a6e1e74
commit
fd43dc6e5d
|
@ -22,15 +22,12 @@ const DB_VERSION_INITIAL = 9
|
||||||
const DB_VERSION_SEARCH_ACCOUNTS = 10
|
const DB_VERSION_SEARCH_ACCOUNTS = 10
|
||||||
const DB_VERSION_CURRENT = 10
|
const DB_VERSION_CURRENT = 10
|
||||||
|
|
||||||
export function getDatabase (instanceName) {
|
if (process.browser) {
|
||||||
if (!instanceName) {
|
require('indexeddb-getall-shim') // needed for Edge
|
||||||
throw new Error('instanceName is undefined in getDatabase()')
|
}
|
||||||
}
|
|
||||||
if (databaseCache[instanceName]) {
|
|
||||||
return Promise.resolve(databaseCache[instanceName])
|
|
||||||
}
|
|
||||||
|
|
||||||
databaseCache[instanceName] = new Promise((resolve, reject) => {
|
function createDatabase (instanceName) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
let req = indexedDB.open(instanceName, DB_VERSION_CURRENT)
|
let req = indexedDB.open(instanceName, DB_VERSION_CURRENT)
|
||||||
openReqs[instanceName] = req
|
openReqs[instanceName] = req
|
||||||
req.onerror = reject
|
req.onerror = reject
|
||||||
|
@ -87,9 +84,17 @@ export function getDatabase (instanceName) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
req.onsuccess = () => resolve(req.result)
|
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]
|
return databaseCache[instanceName]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,6 @@ export const importRequestIdleCallback = () => import(
|
||||||
/* webpackChunkName: 'requestidlecallback' */ 'requestidlecallback'
|
/* webpackChunkName: 'requestidlecallback' */ 'requestidlecallback'
|
||||||
)
|
)
|
||||||
|
|
||||||
export const importIndexedDBGetAllShim = () => import(
|
|
||||||
/* webpackChunkName: 'indexeddb-getall-shim' */ 'indexeddb-getall-shim'
|
|
||||||
)
|
|
||||||
|
|
||||||
export const importWebAnimationPolyfill = () => import(
|
export const importWebAnimationPolyfill = () => import(
|
||||||
/* webpackChunkName: 'web-animations-js' */ 'web-animations-js'
|
/* webpackChunkName: 'web-animations-js' */ 'web-animations-js'
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import {
|
import {
|
||||||
importIntersectionObserver,
|
importIntersectionObserver,
|
||||||
importRequestIdleCallback,
|
importRequestIdleCallback,
|
||||||
importIndexedDBGetAllShim,
|
|
||||||
importWebAnimationPolyfill
|
importWebAnimationPolyfill
|
||||||
} from './asyncModules'
|
} from './asyncModules'
|
||||||
|
|
||||||
|
@ -9,7 +8,6 @@ export function loadPolyfills () {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
typeof IntersectionObserver === 'undefined' && importIntersectionObserver(),
|
typeof IntersectionObserver === 'undefined' && importIntersectionObserver(),
|
||||||
typeof requestIdleCallback === 'undefined' && importRequestIdleCallback(),
|
typeof requestIdleCallback === 'undefined' && importRequestIdleCallback(),
|
||||||
!IDBObjectStore.prototype.getAll && importIndexedDBGetAllShim(),
|
|
||||||
!Element.prototype.animate && importWebAnimationPolyfill()
|
!Element.prototype.animate && importWebAnimationPolyfill()
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue