Skip to content

Instantly share code, notes, and snippets.

@chuyihuang
Last active August 29, 2017 10:29
Show Gist options
  • Save chuyihuang/411b45b95d73311c2de916b619256b48 to your computer and use it in GitHub Desktop.
Save chuyihuang/411b45b95d73311c2de916b619256b48 to your computer and use it in GitHub Desktop.
week_3_demo_6
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