How to use the @react-native-community/async-storage.multiRemove function in @react-native-community/async-storage

To help you get started, we’ve selected a few @react-native-community/async-storage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JetBrains / youtrack-mobile / src / components / storage / storage.js View on Github external
export async function flushStorage(newState: StorageState): Promise {
  // $FlowFixMe Flow doesn't get that it is the same object
  storageState = {...newState};

  const pairsToRemove = Object.entries(storageState)
    .filter(([key, value]) => !hasValue(value));
  await AsyncStorage.multiRemove(pairsToRemove.map((([key]) => storageKeys[key])));

  const pairsToWrite = Object.entries(storageState)
    .filter(([key, value]) => value !== null && value !== undefined);

  if (pairsToWrite.length === 0) {
    log.debug('Storage state is empty, no actuall write has been done');
    return newState;
  }

  const pairs = pairsToWrite
    .map(([key, value]) => [storageKeys[key], hasValue(value) ? JSON.stringify(value) : value]);
  await AsyncStorage.multiSet(pairs);

  return storageState;
}
github crownstone / CrownstoneApp / js / router / store / Persistor.ts View on Github external
.then((allKeys) => {
        let keysToDestroy = {}; // this is map to ensure that we do not delete a key twice
        for (let i = 0; i < pathObjects.length; i++) {
          this._selectMatchingKeys(pathObjects[i], allKeys, keysToDestroy);
        }
        return AsyncStorage.multiRemove(Object.keys(keysToDestroy))
      })
  }
github cheeaun / react-native-cache-store / index.js View on Github external
return AsyncStorage.getItem(exprKey).then((expiry) => {
            if (expiry && currentTime() >= parseInt(expiry, 10)){
              var theKey = CACHE_PREFIX + key.replace(CACHE_EXPIRATION_PREFIX, '');
              return AsyncStorage.multiRemove([exprKey, theKey]);
            }
            return Promise.resolve();
          }).catch(() => {
            return Promise.reject(null);
github jarden-digital / react-native-pincode / src / PinCodeEnter.tsx View on Github external
if (!!this.props.endProcessFunction) {
      this.props.endProcessFunction(pinCode as string)
    } else {
      if (this.props.handleResult) {
        this.props.handleResult(pinCode)
      }
      this.setState({ pinCodeStatus: PinResultStatus.initial })
      this.props.changeInternalStatus(PinResultStatus.initial)
      const pinAttemptsStr = await AsyncStorage.getItem(
        this.props.pinAttemptsAsyncStorageName
      )
      let pinAttempts = pinAttemptsStr ? +pinAttemptsStr : 0
      const pin = this.props.storedPin || this.keyChainResult
      if (pin === pinCode) {
        this.setState({ pinCodeStatus: PinResultStatus.success })
        AsyncStorage.multiRemove([
          this.props.pinAttemptsAsyncStorageName,
          this.props.timePinLockedAsyncStorageName
        ])
        this.props.changeInternalStatus(PinResultStatus.success)
        if (!!this.props.finishProcess)
          this.props.finishProcess(pinCode as string)
      } else {
        pinAttempts++
        if (
          +pinAttempts >= this.props.maxAttempts &&
          !this.props.disableLockScreen
        ) {
          await AsyncStorage.setItem(
            this.props.timePinLockedAsyncStorageName,
            new Date().toISOString()
          )
github morrys / wora / packages / cache-persist / src / storage.native.ts View on Github external
multiRemove: (keys): Promise => {
            return AsyncStorage.multiRemove(keys);
        },
        multiGet: (keys): Promise => {
github kiwicom / mobile / packages / relay / src / CacheManager.js View on Github external
if (parsedData == null) {
        keysToDelete.push(key);
        return;
      }

      const { queryID, variables } = JSON.parse(key.substring(CACHE_KEY.length));

      if (this.isCurrent(parsedData.fetchTime) && cacheSize < CACHE_SIZE) {
        this.cache.set(queryID, variables, parsedData.payload);
        cacheSize++;
      } else {
        keysToDelete.push(key);
      }
    });
    if (keysToDelete.length > 0) {
      AsyncStorage.multiRemove(keysToDelete);
    }
  };
github LedgerHQ / ledger-live-mobile / src / bridge / cache.js View on Github external
export async function clearBridgeCache() {
  const keys = await AsyncStorage.getAllKeys();
  await AsyncStorage.multiRemove(
    keys.filter(k => k.startsWith("bridgeproxypreload")),
  );
}
github cheeaun / react-native-cache-store / index.js View on Github external
return AsyncStorage.getAllKeys().then((keys) => {
      var theKeys = keys.filter((key) => {
        return key.indexOf(CACHE_PREFIX) == 0 || key.indexOf(CACHE_EXPIRATION_PREFIX) == 0;
      });
      return AsyncStorage.multiRemove(theKeys);
    }).catch(() => {
      return Promise.reject(null);
github alphasp / pxview / src / common / store / configureStore.js View on Github external
AsyncStorage.getAllKeys((err, keys) => {
    if (!err && keys && keys.length) {
      const keyPrefix = 'persist:root';
      const v5PersistKeys = keys.filter(key => key.indexOf(keyPrefix) === 0);
      if (v5PersistKeys.length) {
        AsyncStorage.multiRemove(v5PersistKeys, () => Promise.resolve());
      } else {
        const v4KeyPrefix = 'reduxPersist:';
        const v4PersistKeys = keys.filter(
          key => key.indexOf(v4KeyPrefix) === 0,
        );
        if (v4PersistKeys.length) {
          AsyncStorage.multiRemove(v4PersistKeys, () => Promise.resolve());
        }
      }
    }
    return Promise.resolve();
  });
github pd4d10 / echojs-reader / app / context / auth.js View on Github external
const logout = React.useCallback(async () => {
    try {
      await fetchWithAuth(`/logout?apisecret=${secret}`, {
        method: 'POST',
      });
    } catch (err) {
    } finally {
      await AsyncStorage.multiRemove([
        STORAGE_KEYS.auth,
        STORAGE_KEYS.username,
        STORAGE_KEYS.secret,
      ]);
      setAuth(null);
      setUsername(null);
      setSecret(null);
    }
  }, [fetchWithAuth, secret]);