本文整理匯總了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);
})