Skip to content

Commit

Permalink
Remove project root
Browse files Browse the repository at this point in the history
  • Loading branch information
tgolen committed Aug 8, 2020
1 parent e92330c commit 79b39eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
1 change: 0 additions & 1 deletion metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ module.exports = {
},
}),
},
projectRoot: './src',
};
35 changes: 22 additions & 13 deletions src/lib/PersistentStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,47 @@
* 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}`);
});
};

/**
* Write a key to storage
*
* @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,
};

0 comments on commit 79b39eb

Please sign in to comment.