Example in next.js repository shows how we can convert root epic to Promise, so it's possible to await
async action like ajax
:
static async getInitialProps ({ store, isServer }) {
const resultAction = await rootEpic(
of(actions.fetchCharacter(isServer)),
store
).toPromise() // we need to convert Observable to Promise
store.dispatch(resultAction)
return { isServer }
}
I wonder though how it would be possible to await
more than one action. I managed to do it this way:
const actions = await Promise.all([
rootEpic(of(fetchCharacterOne()), store).toPromise(),
rootEpic(of(fetchCharacterTwo()), store).toPromise(),
rootEpic(of(fetchCharacterThree()), store).toPromise(),
]);
actions.forEach(store.dispatch);
...but I wonder if there is a simpler way than calling rootEpic
each time - I mean call it once with three actions to await.