Pass callback to waitForHydration (#3667)

This commit is contained in:
Miguel Alatzar 2019-12-06 12:07:11 -07:00 committed by GitHub
parent 2397224f8e
commit 0b3ba08030
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 21 deletions

View file

@ -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);
}

View file

@ -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);
}