-
Notifications
You must be signed in to change notification settings - Fork 15
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 reducers consuming one action #34
Comments
I've never had a use case for this. Can you provide an example? This actually explicitly forbidden in immer-reducer now: Eg. if the assertion would be removed following would be possible: class Foo1 extends ImmerReducer<State> {
customName = "bar"
setFoo(name: string) {
this.draftState.foo1 = name;
}
}
class Foo2 extends ImmerReducer<State> {
customName = "bar"
setFoo(name: string) {
this.draftState.foo2 = name;
}
} By default immer-reducer generates the action types from the class name & method name but with the But there's reason why this is forbidden: The |
As a workaround I would recommend just dispatching different actions from your async action: dispatch(Actions.setLoadedUserForBar(user));
dispatch(Actions.setLoadedUserForFoo(user)); react-redux now days even exports the batch(() => {
dispatch(Actions.setLoadedUserForBar(user));
dispatch(Actions.setLoadedUserForFoo(user));
}); Also if the actions/reducers are in the same class you can alternatively define a combining action/reducer: setLoaderUser(user: user) {
this.setLoadedUserForBar(user);
this.setLoadedUserForFoo(user);
} |
An easy example (mentioned by redux starter kit) is a That project seems to have similar goals and the way they handle it is by having an |
I see. I'd really like to solve this with decorators too: @action("LOAD_USER")
setUserLoggedIn(user: User) {
// ...
} Where the |
I would also appreciate to have this feature. I use it often in the projects I work on. One is for example https://github.com/FreemapSlovakia/freemap-v3-react and such an action there is for example |
It's a semi-common pattern to have a single action created by an async action (like
LOAD_USER
orUPDATE_FOO
) that multiple reducers listen to and pull state from. It seems like this isn't possible to me withimmer-reducer
. Is this possible, or is there a low boilerplate alternative?The text was updated successfully, but these errors were encountered: