Feature reducer required in multiple places #538
-
Let's take an example of a food delivery app that has feature to track the progress of the delivery on a map after the order is complete. The app allows user to view the order progress from different parts of the app which are also split up into feature modules. Say we have a history of orders feature module, a home/discover feature module. Both of these have the ability to present the progress feature module. Another idea could be to just use the same reducer in multiple composing reducers. This seems much simpler. Something like this:
Can there be any issues in using orderProgressReducer in multiple combining Reducers? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
No, there is absolutely no issue. |
Beta Was this translation helpful? Give feedback.
-
Agree with @tgrapperon, the whole beauty of TCA is that logic i.e. reducers are composable, that is reusable as self-contained modules. So your suggestion to "use the same reducer in multiple composing reducers" is exactly what I do in my own code and I'd suggest doing for you. Sometimes it's worth considering if your feature should be a higher-order reducer (there's relevant thinking in same named Point-Free episode), usually that comes down to understanding is your feature "vertically" or "horizontally" reusable, for example onboarding vs. analytics. |
Beta Was this translation helpful? Give feedback.
No, there is absolutely no issue.
orderProgressReducer
is a free function. It doesn't have an internal state and its whole universe is defined by its arguments, so you can reuse it as freely as the+
operator with different integers.