Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Block root saga until redux is rehydrated (#1139)
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Sutula <[email protected]>
  • Loading branch information
asutula authored Jun 7, 2019
1 parent 8b8f712 commit d6c953c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion App/Redux/configureStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default () => {
const bootstrappedCallback = () => store.dispatch(StartupActions.startup())
const persistor = persistStore(store, undefined, bootstrappedCallback)

sagaMiddleware.run(rootSaga, store.dispatch)
sagaMiddleware.run(rootSaga)

return { store, persistor }
}
29 changes: 26 additions & 3 deletions App/Sagas/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { takeLatest, takeEvery, all, call } from 'redux-saga/effects'
import {
take,
takeLatest,
takeEvery,
all,
call,
select
} from 'redux-saga/effects'
import { PersistedState } from 'redux-persist'
import { getType } from 'typesafe-actions'
import { Dispatch } from 'redux'

/* ------------- Types ------------- */

Expand Down Expand Up @@ -84,7 +91,23 @@ import { startSagas } from './TextileEventsSagas'

/* ------------- Connect Types To Sagas ------------- */

export default function* root(dispatch: Dispatch) {
function* waitForRehydrate() {
const rehydrated = (state: PersistedState) => {
return state._persist ? state._persist.rehydrated : false
}
if (yield select(rehydrated)) {
return
}
while (true) {
yield take('*')
if (yield select(rehydrated)) {
return
}
}
}

export default function*() {
yield call(waitForRehydrate)
yield all([
call(accountSaga),
call(contactsSaga),
Expand Down

0 comments on commit d6c953c

Please sign in to comment.