Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of dispatched actions #1199

Closed
cosminnicula opened this issue Jan 4, 2016 · 2 comments
Closed

Order of dispatched actions #1199

cosminnicula opened this issue Jan 4, 2016 · 2 comments

Comments

@cosminnicula
Copy link

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?

@Sigmus
Copy link

Sigmus commented Jan 4, 2016

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

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

@gaearon
Copy link
Contributor

gaearon commented Jan 4, 2016

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.

@gaearon gaearon closed this as completed Jan 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants