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