Browse Source

[RN] Simplify initialization of AsyncStorage

master
Saúl Ibarra Corretgé 7 years ago
parent
commit
98ff20a026

+ 9
- 14
react/features/app/components/AbstractApp.js View File

105
          * properly initializes. On web it does actually nothing, see
105
          * properly initializes. On web it does actually nothing, see
106
          * {@link #_initStorage}.
106
          * {@link #_initStorage}.
107
          */
107
          */
108
-        this.init = new Promise(resolve => {
109
-            this._initStorage().then(() => {
110
-                this.setState({
111
-                    route: undefined,
112
-                    store: this._maybeCreateStore(props)
113
-                });
114
-                resolve();
108
+        this.init = this._initStorage().then(() => {
109
+            this.setState({
110
+                route: undefined,
111
+                store: this._maybeCreateStore(props)
115
             });
112
             });
116
         });
113
         });
117
     }
114
     }
249
      * @returns {ReactElement}
246
      * @returns {ReactElement}
250
      */
247
      */
251
     _initStorage() {
248
     _initStorage() {
252
-        return new Promise(resolve => {
253
-            if (window.localStorage._initializing) {
254
-                window.localStorage._inited.then(resolve);
255
-            } else {
256
-                resolve();
257
-            }
258
-        });
249
+        if (typeof window.localStorage._initialized !== 'undefined') {
250
+            return window.localStorage._initialized;
251
+        }
252
+
253
+        return Promise.resolve();
259
     }
254
     }
260
 
255
 
261
     /**
256
     /**

+ 1
- 11
react/features/base/lib-jitsi-meet/native/Storage.js View File

34
             // Load all previously persisted data items from React Native's
34
             // Load all previously persisted data items from React Native's
35
             // AsyncStorage.
35
             // AsyncStorage.
36
 
36
 
37
-            /**
38
-             * A flag to indicate that the async {@code AsyncStorage} is not
39
-             * initialized yet. This is native specific but it will work
40
-             * fine on web as well, as it will have no value (== false) there.
41
-             * This is required to be available as we need a sync way to check
42
-             * if the storage is inited or not.
43
-             */
44
-            this._initializing = true;
45
-
46
-            this._inited = new Promise(resolve => {
37
+            this._initialized = new Promise(resolve => {
47
                 AsyncStorage.getAllKeys().then((...getAllKeysCallbackArgs) => {
38
                 AsyncStorage.getAllKeys().then((...getAllKeysCallbackArgs) => {
48
                     // XXX The keys argument of getAllKeys' callback may
39
                     // XXX The keys argument of getAllKeys' callback may
49
                     // or may not be preceded by an error argument.
40
                     // or may not be preceded by an error argument.
77
                             }
68
                             }
78
                         }
69
                         }
79
 
70
 
80
-                        this._initializing = false;
81
                         resolve();
71
                         resolve();
82
                     });
72
                     });
83
                 });
73
                 });

Loading…
Cancel
Save