From 98ff20a026158a83d63880475af8e8ba811f83e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Tue, 16 Jan 2018 16:21:20 +0100 Subject: [PATCH] [RN] Simplify initialization of AsyncStorage --- react/features/app/components/AbstractApp.js | 23 ++++++++----------- .../base/lib-jitsi-meet/native/Storage.js | 12 +--------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/react/features/app/components/AbstractApp.js b/react/features/app/components/AbstractApp.js index 83e8bf48b..1ff8e1c79 100644 --- a/react/features/app/components/AbstractApp.js +++ b/react/features/app/components/AbstractApp.js @@ -105,13 +105,10 @@ export class AbstractApp extends Component { * properly initializes. On web it does actually nothing, see * {@link #_initStorage}. */ - this.init = new Promise(resolve => { - this._initStorage().then(() => { - this.setState({ - route: undefined, - store: this._maybeCreateStore(props) - }); - resolve(); + this.init = this._initStorage().then(() => { + this.setState({ + route: undefined, + store: this._maybeCreateStore(props) }); }); } @@ -249,13 +246,11 @@ export class AbstractApp extends Component { * @returns {ReactElement} */ _initStorage() { - return new Promise(resolve => { - if (window.localStorage._initializing) { - window.localStorage._inited.then(resolve); - } else { - resolve(); - } - }); + if (typeof window.localStorage._initialized !== 'undefined') { + return window.localStorage._initialized; + } + + return Promise.resolve(); } /** diff --git a/react/features/base/lib-jitsi-meet/native/Storage.js b/react/features/base/lib-jitsi-meet/native/Storage.js index f8398fb82..396ecccd5 100644 --- a/react/features/base/lib-jitsi-meet/native/Storage.js +++ b/react/features/base/lib-jitsi-meet/native/Storage.js @@ -34,16 +34,7 @@ export default class Storage { // Load all previously persisted data items from React Native's // AsyncStorage. - /** - * A flag to indicate that the async {@code AsyncStorage} is not - * initialized yet. This is native specific but it will work - * fine on web as well, as it will have no value (== false) there. - * This is required to be available as we need a sync way to check - * if the storage is inited or not. - */ - this._initializing = true; - - this._inited = new Promise(resolve => { + this._initialized = new Promise(resolve => { AsyncStorage.getAllKeys().then((...getAllKeysCallbackArgs) => { // XXX The keys argument of getAllKeys' callback may // or may not be preceded by an error argument. @@ -77,7 +68,6 @@ export default class Storage { } } - this._initializing = false; resolve(); }); });