Added support for nesting in the combineReducers utility method.#214
Added support for nesting in the combineReducers utility method.#214KwintenP wants to merge 1 commit intongrx:masterfrom
Conversation
Added testing for changes made.
|
I like it, I also would like to see multiple reducers for one slice. My scenario is a diagramming application, where you have a lot of actions, e.g. this helps keeping the reducers small. |
|
This seems like a reasonable feature, but I'm increasingly against adding any more complexity to the core of Store, especially as we look into adding lazy-loaded reducers in #211. Is this something we could add to Store or Core as a utility? |
|
Any news on that? has it been released stand-alone? |
|
in my opinion this is rather a syntactic sugar than adding more complexity, which would be helpful if merged |
|
Created a separate npm package for this. Am using it in several project and this way I don't have to copy it over all the time. Would love to see this actually getting into the actual project. You can find it here: https://github.com/KwintenP/combine-reducers-enhanced |
|
I think this is like a "must" feature for a bigger, modular projects which are composed from modules with own store implementations in each that create a tree of different states and reducers for parts of those states. With this all we must do to "enable" such module is importing its reducers object in root app reducers object. Despite limitations it seems to "work", but doesn't initialize states from modules which could effect in code not executing if it relies on store dispatching state with those properties. Solution is dirty and involves creating "Effect" for dispatching initial action to store from this module. Please consider adding it at least as an option to choose between standard "combineReducers". |
Current situation
During design of your state tree, you typically divide it up into different sections. F.e.
NGRX/Store provides the combineReducers method to easily work with such structures.
Problem description
If you want to work with multiple levels of nesting in your state tree, you need to do something else F.e.
In that case, you'd could:
Improvement description
Option 1 provides you with extra work and option 2 forces you to work with a third party library. I personally prefer option 3 where you nest the combineReducers method inside your tree.
This could actually be easily integrated into the current combineReducers method and make the following possible:
It's a lot cleaner than approach where you nest the combineReducers method yourself.
This implemented by making the combineReducers function a recursive one.
Happy to hear any feedback on the feature request/implementation :).
I also created test for this functionality. If you feel these are insufficient or not in the correct place/file, I'm happy to change this as per your instructions.