import client from '../client' const tasks = (state = [], action) => { let updated_tasks; switch (action.type) { case 'LOAD_TASKS': return action.tasks case 'ADD_TASK': return [action.task].concat(state) case 'UPDATE_TASK': updated_tasks = state.map(task => { if (task.id === action.task.id) { return action.task } return task }) return updated_tasks case 'CANCEL_TASK': client.task.destroy(action.task) return state.filter(task => task !== action.task) default: return state } } export default tasks