summaryrefslogtreecommitdiff
path: root/app/infrastructure/application-storage.js
blob: 94307129cde03f526926211817ee291cc330a239 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { AsyncStorage } from 'react-native';

export default class ApplicationStorage {
  fetch(key) {
    return this.safelyRun(() => {
      return AsyncStorage.getItem(key);
    });
  }

  async save(key, value) {
    this.safelyRun(() => {
      AsyncStorage.setItem(key, value);
    });
  }

  delete(key) {
    this.safelyRun(() => {
      AsyncStorage.removeItem(key);
    });
  }

  async safelyRun(block) {
    try {
      return await block();
    } catch (error) {
      console.error(error.message);
    }
  }
}