-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add support for the Saga pattern by enabling multiple actions in a transaction #11
base: master
Are you sure you want to change the base?
Conversation
Why not give each action its own |
Because then I have to keep track of all the IDs of all the actions in that particular transaction. And revert them all one by one. Think of it like a DB transaction. You have a sequence of DB queries, in a transaction, and if any one of them should fail, all should fail. And you roll back the changes. The equivalent of what you're proposing would be to roll back each of the queries on by one. My particular use case is that I am composing my actions from smaller actions, to minimize code repetition inside the reducers. I could make SET_LOADING reducer logic part of the REQUEST_DATA, but I use it in other places, so I'd prefer to compose them rather than duplicate them (the SET_LOADING reducer logic). |
With that pattern, won't you have an entity integrity problem? As i understand it, you have a single If you have multiple PS, if you're doing async work with your own server, I'd suggest you try cashay, which is like relay, but for redux: https://github.com/mattkrick/cashay. it makes life MUCH easier. |
No I have a loading counter, 0 <> +Inf, and a global Loading indicator, which is indicating something is loading if the counter is positive, then I have a per-entity loading boolean, to indicate if that particular entity is currently being loaded. Thank you for the suggestions! I'll check out cashay. So what do you think of these changes? I think they are a nice inexpensive improvement to the current functionality. |
yeah, it looks minimally invasive & i don't see a huge performance hit to include the changes. I'm not sure I understand it 100%, but if you write up a couple unit tests, I can dig in a little more. In the meantime I'll get a TravisCI on this repo |
This sounds awesome. I would love to have multiple actions in a transaction. |
@clayne11 It's not that much code. If you'd like to take over, please go ahead! Right now I unfortunately don't have time to finish this work :( |
NOT FINISHED - DISCUSSION
I want to use this library in combination with Redux Saga. And with Redux Saga, you chain actions to create more complicated UI modifications. These chained actions can be synchronous or asynchronous.
And I want some of these actions to be reversible, and optimistic. To do that I need to be able to revert multiple actions that are part of the same transaction.
With my changes, this is possible. All actions with the same
meta.optimistic.id
get filtered out of the history on a revert.This should be useful for all kinds of asynchronous action libraries where you can chain actions.
E.g.
redux-saga
,redux-thunk
,redux-observable
And of course, all functionality before these changes stays unaffected.