Commit 0a2d0e2

mo khan <mo@mokhan.ca>
2016-11-26 06:08:26
extract a safelyRun block.
1 parent 25ea2c3
Changed files (1)
app/domain/application-storage.js
@@ -1,24 +1,30 @@
 import { View, Text, TouchableHighlight, AsyncStorage } from 'react-native';
 
 export default class ApplicationStorage {
-  async fetch(key) {
-    const value = await AsyncStorage.getItem(key);
-    console.log(`found ${key} ${value}`);
-    return value;
+  fetch(key) {
+    this.safelyRun(() => {
+      const value = AsyncStorage.getItem(key);
+      console.log(`found ${key} ${value}`);
+      return value;
+    });
   }
 
-  async save(key, value) {
-    try {
+  save(key, value) {
+    this.safelyRun(() => {
       console.log(`storing ${key} ${value}`);
       AsyncStorage.setItem(key, value);
-    } catch (error) {
-      console.error(error.message);
-    }
+    });
+  }
+
+  delete(key) {
+    this.safelyRun(() => {
+      AsyncStorage.removeItem(key);
+    });
   }
 
-  async delete(key) {
+  async safelyRun(block) {
     try {
-      await AsyncStorage.removeItem(key);
+      return await block();
     } catch (error) {
       console.error(error.message);
     }