Skip to content

Priority for action dispatches #1680

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

Closed
dariusshop opened this issue Apr 28, 2016 · 5 comments
Closed

Priority for action dispatches #1680

dariusshop opened this issue Apr 28, 2016 · 5 comments

Comments

@dariusshop
Copy link

Hello, have been working with redux for quite a while now. Can honestly say loving it. One thing I noticed that by working with bigger applications that have multiple actions being dispatched via thunks, they always bubble to root. Is there a way to control this without altering the structure? There are some cases, when you want to order Action calls, or force that no other child invoked actions would be called before the current finishes? If its a architecture or a implementation problem, would greatly appreciate some pointers on how to deal with this.

Thanks!

@markerikson
Copy link
Contributor

Can you clarify what you mean by "bubble to root", and "order actions"?

Redux only dispatches a single action at a time. You can technically do another dispatch in the store's subscription callback, but that has to be done conditionally or else you wind up with an infinite loop.

It might also help if you can describe your use case further.

@gaearon
Copy link
Contributor

gaearon commented Apr 28, 2016

Does this help? #1676 (comment)
If you return Promises from thunks, you can chain asynchronous operations.

@dariusshop
Copy link
Author

I will try to provide a detailed view:
The problem i was face'ing was i needed a subscriber to conditionally dispatch a couple of actions on every action made in the application. so The subscriber should go: 1,2,3 then the action that is done via the child Component 4,5,6.
The result i was getting was 1,4,2,3 etc..
Using a promise to resolve and chain did the trick.
Thank You!

@gaearon
Copy link
Contributor

gaearon commented Apr 29, 2016

i needed a subscriber to conditionally dispatch a couple of actions on every action made in the application

I'm afraid this is generally an anti pattern that we don't recommend. Can you tell more about your use case? Why did you need this?

@dariusshop
Copy link
Author

The basic functionality i need is data fetching on state initialization. No matter what route the app is in, it should populate the initial state with data from a certain API. There are cases when the data is page specific, and some where its global to the whole app, like user data on authentication, dynamic sidebar content. this generally sits in the root component and is used by multiple child components. The further expand on the problem i was face'ing, during the initial request, I would normally have a indicators in the state that would tell me if the global data is loaded or needs to be refreshed. This loads of a subscriber. Since the action was a thunk, the initial load, would dispatch a couple of actions one after a another. This would overlap. Firing one action from the subscriber, and one from the components lifecycle ComponentWillMount, this returns a error, since the state does not contain the desired data yet. One other option i could think of was rerendering when the props are present.

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