-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support listenerApi.joinForks() or similar. #3313
Comments
I really haven't used sagas and forking myself, so I don't have the background to compare here. What would be the expected semantics and behavior for a |
Internally creating the fork would keep track of the 'child'. Currently this is implicitly done via https://github.com/reduxjs/redux-toolkit/blob/master/packages/toolkit/src/listenerMiddleware/index.ts#L82-L85 However instead there could be a direct reference in the parent to all created children and I would be happy to provide a demonstration of the change if it is something you are open to, otherwise I will save my time. |
@ericanderson sure, definitely interested! |
Updated version of proposed solution with #3407 function doThingEvent(action, api) {
// lots of code
api.fork((forkApi) => doAnotherThing(forkApi, api), { autoJoin: true });
// lots of code
api.fork((forkApi) => doAnotherThing2(forkApi, api), { autoJoin: true });
// lots of code
if (someCondition) {
api.fork((forkApi) => doAnotherThing3(forkApi, api), { autoJoin: true });
}
// lots of code
if (someCondition2) {
api.fork((forkApi) => doAnotherThing4(forkApi, api), { autoJoin: true });
}
} |
I am examining converting a lot of existing sagas to the listener middleware and I am very excited.
However, I have come across a few gaps that make things challenging. One of those gaps, is that forks are attatched in sagas and there is no such attachment in the listeners. So where no management of forks is needed when writing sagas, you now need to keep track of your forked results so you can await them explicitly.
This effectively requires the code:
In a perfect world, the forks would not stop just because the parent completed, but given how breaking that is, a more helpful alternative could be:
This is much cleaner/easier to read.
The text was updated successfully, but these errors were encountered: