-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
combineReducers
doc does not explain how t gueses which part of state to pass to reducer
#428
Comments
It kinda says it if you read it completely, without skipping:
But I agree this needs to be more prominent, as people often miss this sentence. |
I`d prefer less computer sciency, explicit note about this convention right after example:
I think #399 is good but it's an explanation for Flux users. I'm coming to Redux fresh of the boat. Some form of my text would be more helpful for casual JavaScript developers. Important idea here is: Convention are part of API. It's equally important to Btw, I'm still puzzled how to pass subpart of state to reducer. Should I camelCase join them or something? |
Thanks for feedback, it's very valuable. I want to stress that
is not really true. We should probably just avoid Function names only matter because of how ES6
No :-). It's not a magical API. // Function names don't matter!
function processA(state, action) { ... }
function doSomethingWithB(state, action) { ... }
function reducer(state = {}, action) {
return {
// Because you call them!
a: processA(state.a, action),
b: doSomethingWithB(state.b, action)
};
}
// Not using combineReducers
let store = createStore(reducer); They don't even matter if you use // Function names don't matter!
function processA(state, action) { ... }
function doSomethingWithB(state, action) { ... }
/*
function reducer(state = {}, action) {
return {
a: processA(state.a, action),
b: doSomethingWithB(state.b, action)
};
}
*/
let reducer = combineReducers({
a: processA,
b: doSomethingWithB
});
let store = createStore(reducer); You can do this many times. Before: // Function names don't matter!
function processSomePartOfA(state, action) { ... }
function doSomethingWithOtherPartOfA(state, action) { ... }
function processA(state, action) {
return {
// Because you call them!
somePart: processSomePartOfA(state.somePart),
otherPart: doSomethingWithOtherPartOfA(state.otherPart)
}
}
function doSomethingWithB(state, action) { ... }
function reducer(state = {}, action) {
return {
// Because you call them!
a: processA(state.a, action),
b: doSomethingWithB(state.b, action)
};
}
// Not using the helper
let store = createStore(reducer); You see? It's just functions calling functions. No magic “deep stuff”. // Function names don't matter!
function processSomePartOfA(state, action) { ... }
function doSomethingWithOtherPartOfA(state, action) { ... }
/*
function processA(state, action) {
return {
somePart: processSomePartOfA(state.somePart),
otherPart: doSomethingWithOtherPartOfA(state.otherPart)
}
}
*/
let processA = combineReducers({
somePart: processSomePartOfA,
otherPart: doSomethingWithOtherPartOfA
});
function processA(state, action) { ... }
function doSomethingWithB(state, action) { ... }
/*
function reducer(state = {}, action) {
return {
a: processA(state.a, action),
b: doSomethingWithB(state.b, action)
};
}
*/
let reducer = combineReducers({
a: processA,
b: doSomethingWithB
});
let store = createStore(reducer); The only part where function names matter is when you use I think my biggest mistake here is assuming reader is familiar with named exports. |
I think, assuming reader is familiar with ES6 at all is a stretch. But that's what pushes people to learn and to figure this stuff out. So it's actually a good thing when reading is ahead of the reader's knowledge and experience. |
We're changing examples to explicitly call |
Closing, as this seems to be better addressed in the current docs. |
New combineReducers doc is ok, but it does not explain that you have to name reducer as the party of the state it manages.
The text was updated successfully, but these errors were encountered: