Redux: Order of dispatched actions

Created on 4 Jan 2016  Â·  2Comments  Â·  Source: reduxjs/redux

In the Reddit API example (http://rackt.org/redux/docs/advanced/ExampleRedditAPI.html), handleRefreshClick dispatches two actions invalidateReddit and fetchPostsIfNeeded which should be executed sequentially in order for the code to work correctly - which is something that Redux does not guarantee as far as I know.

My concern is that if fetchPostsIfNeeded is executed before invalidateReddit notifies the reducer to alter the state with didInvalidate = true, then the code will not work correctly..or maybe there's something I'm missing here?

Most helpful comment

dispatches two actions invalidateReddit and fetchPostsIfNeeded which should be executed sequentially in order for the code to work correctly - which is something that Redux does not guarantee as far as I know.

Actions are dispatched synchronously so Redux guarantees the store has received the next state before accepting the next action. Because invalidateReddit is synchronous, any action dispatched from asynchronous fetchPostsIfNeeded is guaranteed to happen after it.

All 2 comments

dispatch(invalidateReddit(selectedReddit))
dispatch(fetchPostsIfNeeded(selectedReddit))

invalidateReddit is invoked before fetchPostsIfNeededand is synchronous so the case you described should never happen.

dispatches two actions invalidateReddit and fetchPostsIfNeeded which should be executed sequentially in order for the code to work correctly - which is something that Redux does not guarantee as far as I know.

Actions are dispatched synchronously so Redux guarantees the store has received the next state before accepting the next action. Because invalidateReddit is synchronous, any action dispatched from asynchronous fetchPostsIfNeeded is guaranteed to happen after it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

caojinli picture caojinli  Â·  3Comments

mickeyreiss-visor picture mickeyreiss-visor  Â·  3Comments

benoneal picture benoneal  Â·  3Comments

CellOcean picture CellOcean  Â·  3Comments

vslinko picture vslinko  Â·  3Comments