-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Multiple Actions one dispatch? #959
Comments
This is probably better handled by using a more generic action type and
just having more reducers listen to it. If there are mutations that would
also trigger after more specific actions are dispatched you can call
functions that do that mutation in multiple reducers.
|
@nhagen is correct, but if you really need to chain multiple actions make them "thenable" dispatch(doThis()) it is also true this would need be in the context of some middleware such as redux-thunk |
Let me come at this from another direction, why is this not a good feature?
|
because the dialog may not truly be open yet, I believe you want a promise like thing in this case |
OPEN_DIALOG is a signal to open the dialog box. Something like this works and has proved effective for me
But the problem is it probably triggers an update between the two commands - which goes unnoticed. |
See:
and also this thread:
Sent from my iPhone
|
But @kswope for the example you gave I think these batching suggestions are more complexity than you may need unless I misunderstand. Ultimately if you have values that need to be prepopulated you should be updating your store in an action right? So I take issue with type: PREPOP_DIALOG, value: 'me@example.com'. It seems semantically imprecise for one thing. Again, this is all shooting from the hip since I only have a small example, but it seems to me that once you have the users email you have an type: ADD_USER_EMAIL, value: 'me@example.com' and that ends up being a prop passed down to the modal. Following this thinking you won't need two actions at the moment you want the modal open because the users' email will already be in the store. |
@jasongonzales23 My assumption was that his Having that as a separate action to make a copy of state for the dialog seems reasonable. You could also use the same action to revert an edit box to its original value if the user clicked a Revert button in the dialog. Avoiding the intermediate rendering is well with the very minimal extra complexity IMO. You set it up once and then it batches all updates automatically and you forget about it because it works way you expect. |
Ah OK, I see. I hadn't thought of it that way, though I wonder if the copy should be made once the user edits? |
Sure, your To do that though, you would need to pass in with the action payload either a reference to the part of the tree state you want to copy (e.g., a path like ['user', 'email']) or the actual reference already obtained through other means, rather than a raw JS value as shown in the example. The other way to avoid copying would be to pass in different part of the state tree (as the props of the dialog) depending on whether an edited value had been set via an action yet. |
The approach we suggest is this: #911 (comment) |
…onality. Ultimately tries to prevent re-renders when multiple states are needed in quick succession.
Unfortunately the last link is now 404. The good one: #911 (comment) |
Is there currently a way to dispatch multiple actions atomically (is that the right term?). I suppose I mean two or more actions sent in succession which only triggers one component update (but of course multiple mutations to the store).
Normally it looks like middleware would be the place for this to happen, but I don't see how the middleware chain can handle more than one action passing through.
I know I can just call multiple dispatches in succession, but I'm not sure of the race condition implications of this - but I do it anyway :)
Thanks!
The text was updated successfully, but these errors were encountered: