-
-
Notifications
You must be signed in to change notification settings - Fork 15.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
feature request: make combineReducers recursive #2022
Comments
Heh. SEARCH THE REPO FOR PREVIOUS ISSUES FIRST! :) :) :) But yeah, this has been brought up numerous times before. See #1768 for the technically-still-open accepted attempt, discussion, and links to previous issues. |
That's not the same thing as what I'm asking. I just want to eliminate extra calls to combineReducers to tighten up my syntax. |
Right, but the issue is that there's been many different alterations to You might want to skim through https://github.com/markerikson/redux-ecosystem-links/blob/master/reducers.md to see if any third-party libs do this already. I think https://github.com/convoyinc/combined-reduction looks fairly close. |
I don't follow the logic... because one or more unrelated feature requests weren't accepted, that no other features should ever be proposed? Looking at your list... I realize a new problem that it would actually take longer to go over that list to see if any meet my needs than to just copy+paste combineReducers and change what I need. I'm not sure how I feel about that. |
The biggest issue is that there's so many different proposals for what extra features should be added to Like many other aspects of Redux (subscription callbacks, |
Part of the trouble is that It's just one of many feasible abstractions that ultimately create what redux core wants --- a single reducer function. Conceptually, I'd be in favor of moving Forgetting redux core for a moment, and just looking at There are competing ideas for what parameters All of that said, rather than copy-pasting Lots of respect for both of you @jimbolla and @markerikson , just sharing my 2 cents. |
Yeah - strictly speaking, The big blocker to any real changes to |
Not sure if I'm using an unsupported feature, but this works: const rootReducer = combineReducers({
taxPage : taxPageReducer
});
export default function taxPageReducer(state = INITIAL_STATE, action) {
return {
...state,
taxSection: taxSectionReducer(state.taxSection, action)
};
}
export default function taxSectionReducer(state = INITIAL_STATE, action) {
switch (action.type) {
case c.FETCH_TAXES_FULFILLED:
state = {...state, records: action.payload};
break;
}
return state;
} It results with the following state: const state = {
taxPage: {
taxSection: {
collapsed: false,
loading: false,
error: false,
records: []
}
}
} |
@davidonlaptop It's perfectly fine for one reducer to delegate work to other functions/reducers as you've done, but I don't see how your code is relevant to the original issue proposed. Perhaps you could clarify. |
@naw I was looking for a solution on nested reducers which could have been solved with recursive reducers. So perhaps it could be of some help to the original author. But you got me there, it is not precisely what is described in the issue. |
@davidonlaptop Thanks for clarifying. Are you under the impression that you can't nest reducers with If so, please be aware that nesting works fine with const rootReducer = combineReducers({
taxPage : taxPageReducer
});
const taxPageReducer = combineReducers({
taxSection: taxSectionReducer
}); Unless you have special circumstances, you shouldn't need the explicit code you wrote above just to achieve nesting. |
Much simpler this way! Thanks @naw! |
Currently, building a reducer with combineReducers looks something like this:
... and it would be nice to be able to do this:
This would reduce some boilerplate.
Implementation should be rather trivial:
I can create test(s) + PR for this if you think it's a good idea.
The text was updated successfully, but these errors were encountered: