Created
July 30, 2016 19:01
-
-
Save IrakliJani/fa456a5bfea04d56808a8b77e486b262 to your computer and use it in GitHub Desktop.
Combine reducers
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
const rootReducer = combineReducers({ | |
user: usersReducer, | |
task: combineReducers({ | |
list: tasksReducer, | |
current: currentTaskReducer | |
}) | |
}) | |
function usersReducer (state = Map(), action) { | |
[...] | |
} | |
function tasksReducer (state = Map(), action) { | |
switch (action.type) { | |
case ADD_TASK: | |
return state.set(action.task.id, action.task) | |
case REMOVE_TASK: | |
return state.delete(action.id) | |
case COMPLETE_TASK: | |
return state.updateIn([action.id, 'completed'], true) | |
default: | |
return state | |
} | |
} | |
function currentTaskReducer (state = null, action) { | |
switch (action.type) { | |
case SET_CURRENT_TASK: | |
return state = action.id | |
case UNSET_CURRENT_TASK: | |
return state = null | |
default: | |
return state | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment