Procházet zdrojové kódy

[RN] Simplify initialization of AsyncStorage

master
Saúl Ibarra Corretgé před 7 roky
rodič
revize
98ff20a026

+ 9
- 14
react/features/app/components/AbstractApp.js Zobrazit soubor

@@ -105,13 +105,10 @@ export class AbstractApp extends Component {
105 105
          * properly initializes. On web it does actually nothing, see
106 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,13 +246,11 @@ export class AbstractApp extends Component {
249 246
      * @returns {ReactElement}
250 247
      */
251 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 Zobrazit soubor

@@ -34,16 +34,7 @@ export default class Storage {
34 34
             // Load all previously persisted data items from React Native's
35 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 38
                 AsyncStorage.getAllKeys().then((...getAllKeysCallbackArgs) => {
48 39
                     // XXX The keys argument of getAllKeys' callback may
49 40
                     // or may not be preceded by an error argument.
@@ -77,7 +68,6 @@ export default class Storage {
77 68
                             }
78 69
                         }
79 70
 
80
-                        this._initializing = false;
81 71
                         resolve();
82 72
                     });
83 73
                 });

Načítá se…
Zrušit
Uložit