本文整理汇总了TypeScript中localforage.getItem函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getItem函数的具体用法?TypeScript getItem怎么用?TypeScript getItem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getItem函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: ionViewDidEnter
ionViewDidEnter(): void {
localforage.getItem("defaultSearch").then((value) => {
console.log(value);
if (value === null) {
this.defaultSearch = "Tame Impala";
}
else {
this.defaultSearch = value.toString();
}
})
}
示例2: return
return Observable.create(observer => {
localforage
.getItem('currentUser')
.then(member => {
if (!member) {
observer.next(false);
return;
}
if (Object.keys(member).length > 1) {
observer.next(member);
} else {
this.findById(member.id)
.subscribe(
memberFound => observer.next(memberFound),
error => {
this.logout()
.subscribe(() => {
observer.next(false);
observer.complete();
});
}
);
}
this.events.subscribe(event => {
if (event.type === 'update' && event.data.id === member.id) {
observer.next(event.data);
}
});
})
.catch(error => observer.error(error));
this.events.subscribe(event => {
if (event.type === 'auth') {
observer.next(event.data);
}
});
return () => {
this.events.unsubscribe();
}
});
示例3:
return Observable.create(observer => {
localforage
.getItem('currentUser')
.then(member => {
if (!member) {
observer.error('No Member Found');
return observer.complete();
}
this.updateById(member.id, data)
.subscribe(updated => {
localforage
.setItem('currentUser', updated)
.then(() => {
observer.next(updated);
observer.complete();
});
});
})
.catch(error => observer.error(error));
});
示例4:
loading.present().then(() => {
localforage.getItem("defaultSearch").then((value) => {
if (value === null) {
this.musicService.getFirstTracks("Tame Impala").then((tracks) => {
this.songs = tracks;
console.log(tracks);
SC.stream(`/tracks/${tracks[0].id}`).then((player) => {
this.initSong = player;
})
loading.dismiss();
})
}
else {
this.musicService.getFirstTracks(value).then((tracks) => {
console.log(tracks);
SC.stream(`/tracks/${tracks[0].id}`).then((player) => {
this.initSong = player;
})
this.songs = tracks;
loading.dismiss();
})
}
})
});
示例5: getLastCharacter
export function getLastCharacter(account: string) {
return localforage.getItem<string | null>(`${account}:lastCharacter`)
}
示例6: getAuthData
export function getAuthData() {
return localforage.getItem<AuthData | null>('authData')
}
示例7: getState
static async getState(userId: string): Promise<State> {
return await localForage.getItem(LocalStore.getKey(userId)) as State;
}
示例8: reject
return new Promise<string>((resolve, reject) => {
LocalForage.getItem<string>(getKey(key), (err, val) => {
return err ? reject(err) : resolve(val);
});
});
示例9: loadCache
async function loadCache(context: Context, projectId: string) {
const items = (await localForage.getItem(getProjectKey(projectId))) || {};
context.setState({ cache: { projectId, items } });
}
示例10: finishLogin
const actions: ActionTree<State, any> = {
async finishLogin ({ commit, dispatch }) {
const parseHash = pify(auth0.parseHash).bind(auth0)
const authResult = await parseHash()
const api = new Api(API_ENDPOINT)
const loginResult = await api.authenticateUser(authResult.accessToken)
commit('RECEIVE_USER', loginResult)
dispatch('storeUser', loginResult)
},
async storeUser (ctx, user) {
await localForage.setItem('user', user)
},
async getStoredUser ({ commit }) {
const user = await localForage.getItem('user')
if (user) commit('RECEIVE_USER', user)
},
async logout ({ commit }) {
await localForage.removeItem('user')
commit('RESET_USER')
},
async getRecipients ({ state, commit }) {
const token = state.user.token
const userId = state.user.id as string
const api = new Api(API_ENDPOINT, token)
const recipients = await api.getRecipients(userId)
commit('RECEIVE_RECIPIENTS', recipients)
}