Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async init() {
this.checkingCache.next(true);
const t0 = performance.now();
console.log('Loading cache');
try {
const key = 'manifest-' + env.versions.app;
const manifest = await get(key);
this.checkingCache.next(false);
// if nothing found, perhaps version has changed, clear old values
if (manifest == null) {
const ks = await keys();
for (const k of ks) {
if (k.toString().startsWith('manifest')) {
del(k);
}
}
await this.load(key);
} else {
this.cache = manifest;
}
this.percent.next(100);
this.ready.next(true);
const t1 = performance.now();
console.log((t1 - t0) + ' ms to load manifest');
} catch (exc) {
async (action: GenericAction) => {
if (isActionOfType(action, 'LOAD_PERSISTED_STATE_REQUESTED')) {
console.info('Requested loading persisted state');
next(action);
try {
const keys = await idb.keys();
let restoredState: RestoredState = { };
if (keys.length === 0) {
console.info('No persisted state was found.');
} else if (indexOf(keys, __VERSION__) > -1) {
console.info(`Found persisted state compatible with this version (${__VERSION__})`);
restoredState = await idb.get(__VERSION__);
} else {
console.info(
`Could not find persisted state compatible with this ` +
`version (${__VERSION__}). Upgrading...`,
);
next(persistStateUpgradeStarted(void 0));
// @TODO: perform any necessary upgrade operations
await idb.clear(); // @FIXME: Workaround
// @NOTE: Do not break on switch cases.
switch (__VERSION__) {
private async load(overridePveUrl: string, overridePvpUrl: string): Promise {
const t0 = performance.now();
const key = 'wishlist-' + env.versions.app + '-' + overridePveUrl + '-' + overridePvpUrl;
let rolls: CuratedRoll[] = await get(key);
if (rolls == null || rolls.length==0) {
console.log(' No cached wishlists: ' + key);
// clear cache
const ks = await keys();
for (const k of ks) {
if (k.toString().startsWith('wishlist')) {
del(k);
}
}
const pveRolls = await this.loadSingle('pve', overridePveUrl, WishlistService.DEFAULT_PVE_URL);
const pvpRolls = await this.loadSingle('pvp', overridePvpUrl, WishlistService.DEFAULT_PVP_URL);
rolls = pveRolls.concat(pvpRolls);
set(key, rolls);
console.log(' Wishlists downloaded, parsed and saved.');
} else {
console.log(' Using cached wishlists: ' + key);
}
const t1 = performance.now();
console.log((t1 - t0) + ' ms to load wishlists');
return rolls;
function deleteCachedVendors() {
// Everything's in one table, so we can't just clear
idbKeyval.keys().then((keys) => {
keys.forEach((key) => {
if (key.startsWith('vendor')) {
idbKeyval.delete(key);
}
});
});
}
.then(response => {
if (response.error) {
throw new Error(response.error.message);
}
const voices = new Map();
response.voices.forEach(voice => {
voice.isWaveNet = voice.name.indexOf('Wavenet') >= 0;
voice.gender = capitalize(voice.ssmlGender);
voices.set(voice.name, voice);
});
// store voices in indexedDB
return idbKeyval.keys(voicesCacheDB)
.then(oldKeys => {
const promises = Array.from(voices.values())
.map(voice => idbKeyval.set(voice.name, voice, voicesCacheDB));
// remove any deleted voices
oldKeys.forEach(key => {
if (!voices.has(key)) {
promises.push(idbKeyval.del(key, voicesCacheDB));
}
});
return Promise.all(promises).then(() => voices);
});
})
.catch(err => {
get: () => idbKeyval.keys(),
},
get: () => idbKeyval.keys().then(keys => Promise.all(keys.map(key => idbKeyval.get(key)))),
},
} else if (_keys.constructor === String) {
ks = [_keys];
} else if (_keys.constructor === Array) {
ks = _keys;
}
ks.forEach((key) => {
get(key, localStorage).then((val: any) => {
let tmp = null;
if (val !== undefined) {
tmp = JSON.parse(val);
}
ret[key] = (tmp !== null) ? tmp : ret[key];
});
});
} else {
keys(localStorage).then((_keys) => {
_keys.forEach((key) => {
get(key, localStorage).then((val: any) => {
let tmp = null;
if (val !== undefined) {
tmp = JSON.parse(val);
}
ret[(key as any)] = tmp;
if (ret[(key as any)] === null) {
ret[(key as any)] = undefined;
}
});
});
});
}
if (callback) {
run: async (dispatch, { user }) => {
const keys = await idk.keys();
if (keys.length === 0) {
return [
{
title: `…you don't have any locally saved bins`,
},
];
}
const now = Date.now();
const remoteBins = getBins(user).then(bins => {
if (!Array.isArray(bins)) {
return [];
}
return bins.map(bin => {
db.set(key, val, store)
.then(() => self.postMessage(true))
.catch(() => self.postMessage(false))
break
case 'del':
db.del(key, store)
.then(() => self.postMessage(true))
.catch(() => self.postMessage(false))
break
case 'clr':
db.clear(store)
.then(() => self.postMessage(true))
.catch(() => self.postMessage(false))
break
case 'keys':
db.keys(store)
.then((res) => self.postMessage(res))
.catch(() => self.postMessage(false))
break
}
})