Skip to content

Instantly share code, notes, and snippets.

@camwest
Created May 15, 2016 00:47
Show Gist options
  • Save camwest/e95564228344d7b82f2f4d1cd1ed508f to your computer and use it in GitHub Desktop.
Save camwest/e95564228344d7b82f2f4d1cd1ed508f to your computer and use it in GitHub Desktop.
function rootReducer(state, action) {
return {
part1: part1Reducer(state.part1, action),
part2: part2Reducer(state.part2, action)
}
}
function part1Reducer(state, action) {
return {
part1A: part1AReducer(state.A, action),
part1B: part1BReducer(state.B, action)
}
}
function part1AReducer(state, action) {
return 'bar';
}
function part1BReducer(state, action) {
return 'baz'
}
function part2Reducer(state, action) {
return 'foo';
}
const state = {};
const action = {type: 'my action'};
const next = rootReducer(state, action);
` result looks like:
{
part1: {
part1A: 'bar',
part1B: 'baz'
},
part2: 'foo'
}
`
// rootReducer knows about part1, part2
// part1 knows about part1A, part1B
// this is a "top down" architecture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment