Just diving into Redux saga.
I'm working on creating a saga that will fetch the initial state for the redux store from our API server.
This task involves utilizing two asynchronous sagas: getCurrentUser
and getGroups
.
The goal is to send these ajax requests simultaneously, then wait for the GET_CURRENT_USER_SUCCESS
and GET_GROUPS_SUCCESS
actions before triggering the pageReady
action, signaling the UI to start rendering the react components.
I've come up with a workaround solution:
function * loadInitialState () {
yield fork(getCurrentUser)
yield fork(getGroups)
while (true) {
yield take([
actions.GET_GROUPS_SUCCESS,
actions.GET_CURRENT_USER_SUCCESS
])
yield take([
actions.GET_GROUPS_SUCCESS,
actions.GET_CURRENT_USER_SUCCESS
])
yield put(actions.pageReady())
}
}
The issue with this code arises if GET_GROUPS_SUCCESS
is dispatched twice, causing the pageReady
action to fire prematurely.
Is there a way to instruct redux saga to hold off until both GET_GROUPS_SUCCESS
and GET_CURRENT_USER_SUCCESS
have occurred at least once in any order?