From 79b39eb29bbe46cfb16c832861fedac4b934cb0d Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Sat, 8 Aug 2020 10:16:13 -0600 Subject: [PATCH] Remove project root --- metro.config.js | 1 - src/lib/PersistentStorage.js | 35 ++++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/metro.config.js b/metro.config.js index bcbc37660496..783f3499c2cb 100644 --- a/metro.config.js +++ b/metro.config.js @@ -14,5 +14,4 @@ module.exports = { }, }), }, - projectRoot: './src', }; diff --git a/src/lib/PersistentStorage.js b/src/lib/PersistentStorage.js index 7cca31d69462..925f61fb3d32 100644 --- a/src/lib/PersistentStorage.js +++ b/src/lib/PersistentStorage.js @@ -2,21 +2,23 @@ * This module is an abstraction around a persistent storage system. This file can be modified to use whatever * persistent storage method is desired. */ - import AsyncStorage from '@react-native-community/async-storage'; /** * Get a key from storage * * @param {string} key + * @returns {Promise} */ -const get = async (key) => { - try { - const jsonValue = await AsyncStorage.getItem(key); - return jsonValue != null ? JSON.parse(jsonValue) : null; - } catch (e) { - console.error(`Could not parse value from local storage. Key: ${key}`); - } +function get(key) { + return AsyncStorage.getItem(key) + .then(val => { + const jsonValue = JSON.parse(val); + return jsonValue; + }) + .catch(err => { + console.error(`Unable to get item from persistent storage. Key: ${key} Error: ${err}`); + }); }; /** @@ -24,16 +26,23 @@ const get = async (key) => { * * @param {string} key * @param {mixed} val + * @returns {Promise} */ -const set = async (key, val) => { - await AsyncStorage.setItem(key, JSON.stringify(val)); +function set(key, val) { + return AsyncStorage.setItem(key, JSON.stringify(val)); }; /** * Empty out the storage (like when the user signs out) + * + * @returns {Promise} */ -const clear = async () => { - await AsyncStorage.clear(); +function clear() { + return AsyncStorage.clear(); }; -export {get, set, clear}; +export { + get, + set, + clear, +};