simplify getProxy

This commit is contained in:
tophf 2022-02-23 09:12:41 +03:00
parent e567b6d56d
commit d2a99b5be1

View File

@ -30,11 +30,9 @@ const db = (() => {
}; };
/** /**
* @param {string} dbName * @param {string} dbName
* @param {boolean} [idAsKey] - if true, only objects can be stored with a unique `id` property
* @return {IDBObjectStore | {putMany: function(items:?[]):Promise<?[]>}} * @return {IDBObjectStore | {putMany: function(items:?[]):Promise<?[]>}}
*/ */
const getProxy = (dbName, idAsKey) => proxies[dbName] || ( const getProxy = dbName => proxies[dbName] || (
(ID_AS_KEY[dbName] = idAsKey),
(proxies[dbName] = new Proxy({dbName}, proxyHandler)) (proxies[dbName] = new Proxy({dbName}, proxyHandler))
); );
addAPI(/** @namespace API */ { addAPI(/** @namespace API */ {
@ -44,7 +42,7 @@ const db = (() => {
prefsDb: getProxy(prefs.STORAGE_KEY), prefsDb: getProxy(prefs.STORAGE_KEY),
}); });
return { return {
styles: getProxy(DB, true), styles: getProxy(DB),
}; };
async function cachedExec(dbName, cmd, a, b) { async function cachedExec(dbName, cmd, a, b) {