Last active
August 29, 2017 10:29
-
-
Save chuyihuang/411b45b95d73311c2de916b619256b48 to your computer and use it in GitHub Desktop.
week_3_demo_6
This file contains 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
import * as Types from '../types'; | |
const initialState = []; | |
export default function(state = initialState, action = {}) { | |
switch (action.type) { | |
case Types.ADD_TODO: | |
return [...state , action.payload]; | |
case Types.TOGGLE_TODO: | |
let filteredTodos = state.filter((todo) => todo.id !== action.payload.id); | |
return [...filteredTodos, {...action.payload, checked: !action.payload.checked}].sort((a,b) => a.id > b.id); | |
} | |
return state; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment