本文整理汇总了TypeScript中idb-keyval.set函数的典型用法代码示例。如果您正苦于以下问题:TypeScript set函数的具体用法?TypeScript set怎么用?TypeScript set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: calculateExpiration
.then((vendor: Vendor) => {
vendor.expires = calculateExpiration(vendor.nextRefreshDate, vendorHash);
vendor.factionLevel = factionLevel(store, vendorDef.summary.factionHash);
vendor.factionAligned = factionAligned(store, vendorDef.summary.factionHash);
return set(key, vendor)
.catch(handleLocalStorageFullError)
.then(() => vendor);
})
示例2: getAwaToken
export async function getAwaToken(
account: DestinyAccount,
action: AwaType,
item?: D2Item
): Promise<string> {
if (!awaCache) {
// load from cache first time
awaCache = ((await idbKeyval.get('awa-tokens')) || {}) as {
[key: number]: AwaAuthorizationResult & { used: number };
};
}
let info = awaCache[action];
if (!info || !tokenValid(info)) {
try {
// Note: Error messages should be handled by other components. This is just to tell them to check the app.
toaster.pop('info', t('AWA.ConfirmTitle'), t('AWA.ConfirmDescription'));
info = awaCache[action] = {
...(await requestAdvancedWriteActionToken(account, action, item)),
used: 0
};
// Deletes of "group A" require an item and shouldn't be cached
// TODO: This got removed from the API
/*
if (action === AwaType.DismantleGroupA) {
delete awaCache[action]; // don't cache
}
*/
} catch (e) {
throw new Error('Unable to get a token: ' + e.message);
}
if (!info || !tokenValid(info)) {
throw new Error('Unable to get a token: ' + info ? info.developerNote : 'no response');
}
}
info.used++;
// TODO: really should use a separate db for this
await idbKeyval.set('awa-tokens', awaCache);
return info.actionToken;
}
示例3: factionLevel
.catch((e) => {
// console.log("vendor error", vendorDef.summary.vendorName, 'for', store.name, e, e.code, e.status);
if (e.status === 'DestinyVendorNotFound') {
const vendor = {
failed: true,
code: e.code,
status: e.status,
expires: Date.now() + 60 * 60 * 1000 + (Math.random() - 0.5) * (60 * 60 * 1000),
factionLevel: factionLevel(store, vendorDef.summary.factionHash),
factionAligned: factionAligned(store, vendorDef.summary.factionHash)
};
return idbKeyval.set(key, vendor).then(() => {
throw new Error(`Cached failed vendor ${vendorDef.summary.vendorName}`);
});
}
throw new Error(`Failed to load vendor ${vendorDef.summary.vendorName}`);
});
示例4: getAwaToken
export async function getAwaToken(account: DestinyAccount, action: AwaType, item?: DimItem): Promise<string> {
if (!awaCache) {
// load from cache first time
awaCache = (await idbKeyval.get('awa-tokens') || {}) as {
[key: number]: AwaAuthorizationResult & { used: number };
};
}
let info = awaCache[action];
if (!info || !tokenValid(info)) {
try {
info = awaCache[action] = {
...await requestAdvancedWriteActionToken(account, action, item),
used: 0
};
// Deletes of "group A" require an item and shouldn't be cached
if (action === AwaType.DismantleGroupA) {
delete awaCache[action]; // don't cache
}
// TODO: really should use a separate db for this
// without blocking, save this
idbKeyval.set('awa-tokens', awaCache);
} catch (e) {
throw new Error("Unable to get a token: " + e.message);
}
if (!info || !tokenValid(info)) {
throw new Error("Unable to get a token: " + info ? info.developerNote : "no response");
}
}
info.used++;
return info.actionToken;
}
示例5: loadNewItems
});
},
loadNewItems(account: DestinyAccount): Promise<Set<string>> {
if (account) {
const key = newItemsKey(account);
return Promise.resolve(idbKeyval.get(key)).then(
(v) => (v as Set<string>) || new Set<string>()
);
}
return Promise.resolve(new Set<string>());
},
saveNewItems(newItems: Set<string>, account: DestinyAccount) {
store.dispatch(setNewItems(newItems));
return Promise.resolve(idbKeyval.set(newItemsKey(account), newItems));
},
buildItemSet(stores) {
const itemSet = new Set();
stores.forEach((store) => {
store.items.forEach((item) => {
itemSet.add(item.id);
});
});
return itemSet;
},
applyRemovedNewItems(newItems: Set<string>) {
_removedNewItems.forEach((id) => newItems.delete(id));
_removedNewItems.clear();
示例6: set
.then((remoteData: ClassifiedData) => {
remoteData.time = Date.now();
// Don't wait for the set - for some reason this was hanging
set('classified-data', remoteData).catch(handleLocalStorageFullError);
return remoteData;
})
示例7:
.then((remoteData: ClassifiedData) => {
remoteData.time = Date.now();
// Don't wait for the set - for some reason this was hanging
idbKeyval.set('classified-data', remoteData);
return remoteData;
})
示例8: Set
return;
}
store.dispatch(setNewItems(new Set()));
this.saveNewItems(new Set(), account);
},
loadNewItems(account: DestinyAccount): Promise<Set<string>> {
if (account) {
const key = newItemsKey(account);
return Promise.resolve(get(key)).then((v) => (v as Set<string>) || new Set<string>());
}
return Promise.resolve(new Set<string>());
},
saveNewItems(newItems: Set<string>, account: DestinyAccount) {
return Promise.resolve(set(newItemsKey(account), newItems)).catch(handleLocalStorageFullError);
},
buildItemSet(stores) {
const itemSet = new Set();
stores.forEach((store) => {
store.items.forEach((item) => {
itemSet.add(item.id);
});
});
return itemSet;
},
applyRemovedNewItems(newItems: Set<string>) {
_removedNewItems.forEach((id) => newItems.delete(id));
_removedNewItems.clear();
示例9: calculateExpiration
.then((vendor: Vendor) => {
vendor.expires = calculateExpiration(vendor.nextRefreshDate, vendorHash);
vendor.factionLevel = factionLevel(store, vendorDef.summary.factionHash);
vendor.factionAligned = factionAligned(store, vendorDef.summary.factionHash);
return idbKeyval.set(key, vendor).then(() => vendor);
})