Last active
March 20, 2017 22:39
-
-
Save StevenJL/e1fb81d0337c1b480140 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
| // the convention here is to name the reducer function the same | |
| // name as the property in the state object that it is modifying | |
| // this function modifies the visibilityFilter, hence it's | |
| // named as such | |
| function visibilityFilter(state="SHOW_ALL", action){ | |
| // basically the same code and logic found in | |
| // the "SET_VISIBILITY_FILTER" case statement | |
| } | |
| function todos(state=[], action){ | |
| // basically the same code and logic found in | |
| // the "UPDATE_TODO" and "ADD_TODO" case statements | |
| } | |
| // the convention for the "main reducer function" | |
| // is to name it with the "App" suffix | |
| // In this case, we name it `todoApp` | |
| function todoApp(state=initialState, action){ | |
| return { | |
| visibilityFilter: visibilityFilter(state.visibilityFilter, action), | |
| todos: todos(state.todos, action) | |
| } | |
| } | |
| // A note of caution: In the above example, we decomposed the above reducer | |
| // into the constituent reducers `visibilityFilter` and `todos`. We were able | |
| // to do this because these two reducers handled different parts of the state | |
| // object independently. This may not always be the case, so you gotta be careful. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment