From 0b3ba08030846dd1018eba8f5e60805e676ca017 Mon Sep 17 00:00:00 2001 From: Miguel Alatzar Date: Fri, 6 Dec 2019 12:07:11 -0700 Subject: [PATCH] Pass callback to waitForHydration (#3667) --- app/mattermost.js | 9 +++++---- app/store/utils.js | 25 ++++++++----------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/app/mattermost.js b/app/mattermost.js index 738c3b576..f89a654e0 100644 --- a/app/mattermost.js +++ b/app/mattermost.js @@ -48,16 +48,17 @@ const init = async () => { } }; -const launchApp = async (credentials) => { +const launchApp = (credentials) => { telemetry.start([ 'start:select_server_screen', 'start:channel_screen', ]); if (credentials) { - await waitForHydration(store); - store.dispatch(loadMe()); - resetToChannel({skipMetrics: true}); + waitForHydration(store, () => { + store.dispatch(loadMe()); + resetToChannel({skipMetrics: true}); + }); } else { resetToSelectServer(emmProvider.allowOtherServers); } diff --git a/app/store/utils.js b/app/store/utils.js index bd94cc917..192b70826 100644 --- a/app/store/utils.js +++ b/app/store/utils.js @@ -42,23 +42,14 @@ export function transformSet(incoming, setTransforms, toStorage = true) { } export function waitForHydration(store, callback) { - let unsubscribeFromStore; - return new Promise((resolve) => { - if (__DEV__) { - // when in DEV mode resetting the app can get into a white screen - resolve(); - return; - } - const subscription = () => { - if (store.getState().views.root.hydrationComplete) { - unsubscribeFromStore(); - if (callback && typeof callback === 'function') { - callback(); - } - resolve(); + const subscription = () => { + if (store.getState().views.root.hydrationComplete) { + unsubscribeFromStore(); + if (callback && typeof callback === 'function') { + callback(); } - }; + } + }; - unsubscribeFromStore = store.subscribe(subscription); - }); + const unsubscribeFromStore = store.subscribe(subscription); } \ No newline at end of file