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