Created
October 5, 2016 12:25
-
-
Save mattiamanzati/fdf987121f3f125ad28561b7d8961437 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
// initial state | |
const initialState = { | |
left: CounterPair.reducer(), | |
right: CounterPair.reducer(), | |
count: 0 | |
} | |
// listen to any action of subcomponents | |
const appReducer = createReducer( | |
initialState, | |
{ | |
[Counter.INCREMENT]: state => updateProperty(state, 'count', state.count + 1) | |
} | |
) | |
// actual reducer | |
export const reducer = (state = initialState, action) => { | |
// child reducers | |
state = updateProperty(state, 'left', CounterPair.reducer(state.left, actionFor(LEFT, action))) | |
state = updateProperty(state, 'right', CounterPair.reducer(state.right, actionFor(RIGHT, action))) | |
// listen to any children event | |
return appReducer(state, unwrap(action)) | |
} | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment