本文整理匯總了TypeScript中localforage.setItem函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript setItem函數的具體用法?TypeScript setItem怎麽用?TypeScript setItem使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了setItem函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
handler: data => {
localforage.setItem("defaultSearch", data.term).then((value) => {
this.defaultSearch = value;
}).catch((err) => {
console.log(err);
})
}
示例2:
const runTestScenario = () =>
localforage
.setItem('UserProfile', {
UserName: 'user1',
Password: '12345',
})
.then(() =>
localforage.setItem('UserProfile', {
UserName: 'user1',
Password: '67890',
}),
)
// this should not notify the subscribers
.then(() =>
localforage.setItem('UserProfile', {
UserName: 'user1',
Password: '67890',
}),
)
.then(() => localforage.setItem('test1', 'value1'))
.then(() => localforage.setItem('test2', 'value2'))
.then(() => localforage.setItem('test2', 'value2b'))
// this should not notify subscribers w/ changeDetection
.then(() => localforage.setItem('test2', 'value2b'))
.then(() => localforage.setItem('test3', 'value3'))
.then(() => localforage.removeItem('test3'))
.then(() => localforage.removeItem('test3'))
.then(() => localforage.clear())
// this should not notify subscribers w/ changeDetection
.then(() => localforage.clear());
示例3:
.then(function() {
// this should not notify the subscribers
return localforage.setItem('UserProfile', {
UserName: 'user1',
Password: '67890',
});
})
示例4:
.subscribe(updated => {
localforage
.setItem('currentUser', updated)
.then(() => {
observer.next(updated);
observer.complete();
});
});
示例5: setItem
function setItem(context: Context, key: string, value: any) {
const { cache } = context.getState();
if (!cache) {
throw new Error(`Can't set item "${key}" before loading storage`);
}
const { projectId, items } = cache;
const newItems = { ...items, [key]: value };
context.setState({ cache: { projectId, items: newItems } });
localForage.setItem(getProjectKey(projectId), newItems);
}
示例6:
const runTestScenario = () =>
localforage
.setItem('test1', 'value1')
.then(() => localforage.setItem('test2', 'value2'))
.then(() => localforage.setItem('test2', 'value2b'))
.then(() => localforage.setItem('test2', 'value2b'))
.then(() => localforage.setItem('test3', 'value3'))
.then(() => localforage.removeItem('test3'))
.then(() => localforage.removeItem('test3'))
.then(() => localforage.clear())
.then(() => localforage.clear());
示例7: setState
static async setState(userId: string, state: State): Promise<void> {
await localForage.setItem(LocalStore.getKey(userId), state);
}