本文整理汇总了TypeScript中react-native.AsyncStorage.setItem方法的典型用法代码示例。如果您正苦于以下问题:TypeScript AsyncStorage.setItem方法的具体用法?TypeScript AsyncStorage.setItem怎么用?TypeScript AsyncStorage.setItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类react-native.AsyncStorage
的用法示例。
在下文中一共展示了AsyncStorage.setItem方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: finalizeLogIn
/**
* this should be called when the setup procedure has been successful
* @param userId
* @returns {*|Promise.<TResult>}
*/
finalizeLogIn(userId) {
// write to database that we are logged in.
return AsyncStorage.setItem(LOGGED_IN_USER_ID_STORAGE_KEY, userId)
.catch((err) => {
LOGe.store("StoreManager: finalize login failed. ", err);
})
}
示例2: setConsent
public setConsent(consent: IDataPolicyConsent) {
const serializedProgress = JSON.stringify(consent);
return AsyncStorage.setItem(
DataPolicyConsentStorage.getKey(),
serializedProgress
);
}
示例3: getCacheCurSize
/**
* return the current size of the cache
* @return {Promise}
*/
async getCacheCurSize() {
let ret = await AsyncStorage.getItem(this.cacheCurSizeKey);
if (!ret) {
await AsyncStorage.setItem(this.cacheCurSizeKey, '0');
ret = '0';
}
return Number(ret);
}
示例4: _setItem
/**
* put item into cache
* @private
* @param prefixedKey - the key of the item
* @param itemData - the value of the item
* @param itemSizeInBytes - the byte size of the item
*/
async _setItem(prefixedKey, item) {
// first try to update the current size of the cache.
await this._increaseCurSizeInBytes(item.byteSize);
// try to add the item into cache
try {
await AsyncStorage.setItem(prefixedKey, JSON.stringify(item));
} catch (setItemErr) {
// if some error happened, we need to rollback the current size
await this._decreaseCurSizeInBytes(item.byteSize);
logger.error(`Failed to set item ${setItemErr}`);
}
}
示例5: setProgress
public setProgress(id: string, progress: ISerializedProgress) {
const serializedProgress = JSON.stringify(progress);
return AsyncStorage.setItem(this.getKey(id), serializedProgress);
}
示例6: set
static set(key, value) {
return AsyncStorage.setItem(key, JSON.stringify(value))
}
示例7:
.then(() => {
return AsyncStorage.setItem(this.userIdentificationStorageKey, "");
})
示例8: _refreshItem
/**
* update the visited time if item has been visited
* @private
* @param item - the item which need to be refreshed
* @param prefixedKey - the key of the item
*
* @return the refreshed item
*/
async _refreshItem(item, prefixedKey) {
item.visitedTime = getCurrTime();
await AsyncStorage.setItem(prefixedKey, JSON.stringify(item));
return item;
}
示例9: _increaseCurSizeInBytes
/**
* increase current size of the cache
* @private
* @param amount - the amount of the cache szie which need to be increased
*/
async _increaseCurSizeInBytes(amount) {
const curSize = await this.getCacheCurSize();
await AsyncStorage.setItem(this.cacheCurSizeKey, (curSize + amount).toString());
}
示例10:
snapshot => AsyncStorage.setItem(storageKey, JSON.stringify(snapshot)),