Triggering effects from child #3648
arkulpaKonstantin
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We are currently working on an App that needs to trigger some functionality in the root reducer from many child reducers and child of child of child ... reducers.
To handle this we used to listen to all the child actions and then trigger the functionality, but as that got really confusing and a lot of boilerplate for every new child action we added something like the
dismiss
functionality for this case.I thought I would share this and suggest to make it more general with some hashable ID or so.
One issue we ran into is that in tests the effect is expected to finish. But one can not for now do that so we have to use
skipInFlightEffects
.Here is our code. (As you may guess the functionality we need has to do with the parent reducer doing a restart 😅)
The effect:
The reducer modifier:
The root reducer then just adds this line:
Then then all the children can use the dependency like so:
and simply restart the root reducer by returning a run effect that calls the restart:
Beta Was this translation helpful? Give feedback.
All reactions