本文整理匯總了TypeScript中react-native.AsyncStorage.removeItem方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript AsyncStorage.removeItem方法的具體用法?TypeScript AsyncStorage.removeItem怎麽用?TypeScript AsyncStorage.removeItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類react-native.AsyncStorage
的用法示例。
在下文中一共展示了AsyncStorage.removeItem方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: _removeItem
/**
* delete item from cache
* @private
* @param prefixedKey - the key of the item
* @param size - optional, the byte size of the item
*/
async _removeItem(prefixedKey, size?) {
const itemSize = size? size : (JSON.parse(await AsyncStorage.getItem(prefixedKey))).byteSize;
// first try to update the current size of the cache
await this._decreaseCurSizeInBytes(itemSize);
// try to remove the item from cache
try {
await AsyncStorage.removeItem(prefixedKey);
} catch (removeItemError) {
// if some error happened, we need to rollback the current size
await this._increaseCurSizeInBytes(itemSize);
logger.error(`Failed to remove item: ${removeItemError}`);
}
}
示例2: clear
/**
* clear the entire cache
* The cache will abort output a warning:
* If error happened with AsyncStorage
* @return {Promise}
*/
async clear() {
logger.debug(`Clear Cache`);
try {
const keys = await AsyncStorage.getAllKeys();
const keysToRemove = [];
for (let i = 0; i < keys.length; i += 1) {
if (keys[i].indexOf(this.config.keyPrefix) === 0) {
keysToRemove.push(keys[i]);
}
}
// can be improved
for (let i = 0; i < keysToRemove.length; i += 1) {
await AsyncStorage.removeItem(keysToRemove[i]);
}
} catch (e) {
logger.warn(`clear failed! ${e}`);
}
}
示例3: remove
static remove(key) {
return AsyncStorage.removeItem(key)
}