master
 1import { AsyncStorage } from 'react-native';
 2
 3export default class ApplicationStorage {
 4  fetch(key) {
 5    return this.safelyRun(() => {
 6      return AsyncStorage.getItem(key);
 7    });
 8  }
 9
10  async save(key, value) {
11    this.safelyRun(() => {
12      AsyncStorage.setItem(key, value);
13    });
14  }
15
16  delete(key) {
17    this.safelyRun(() => {
18      AsyncStorage.removeItem(key);
19    });
20  }
21
22  async safelyRun(block) {
23    try {
24      return await block();
25    } catch (error) {
26      console.error(error.message);
27    }
28  }
29}