MM-21085 Updated waitHydration (#3677)

* MM-21085 Updated waitHydration

Updated the hydration of hte store to first check if it completed as this was being caused due to a race condition.

* MM-21085 Updated for callback

MM-21085 Updated for callback
This commit is contained in:
CJ 2019-12-09 14:54:41 -05:00 committed by Elias Nahum
parent 29c27417bd
commit 1ac82b8df2

View file

@ -42,14 +42,20 @@ export function transformSet(incoming, setTransforms, toStorage = true) {
}
export function waitForHydration(store, callback) {
const subscription = () => {
if (store.getState().views.root.hydrationComplete) {
unsubscribeFromStore();
if (callback && typeof callback === 'function') {
callback();
}
if (store.getState().views.root.hydrationComplete) {
if (callback && typeof callback === 'function') {
callback();
}
};
} else {
const subscription = () => {
if (store.getState().views.root.hydrationComplete) {
unsubscribeFromStore();
if (callback && typeof callback === 'function') {
callback();
}
}
};
const unsubscribeFromStore = store.subscribe(subscription);
const unsubscribeFromStore = store.subscribe(subscription);
}
}