Guest User

Untitled

a guest
Apr 25th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. /* eslint-disable fp/no-nil */
  2. import { ADD_TODO, REMOVE_TODO } from './actions'
  3.  
  4. export default (state = { todos: [] }, action) => {
  5. switch (action.type) {
  6. case ADD_TODO: {
  7. const newTodo = {
  8. id: state.todos.reduce((maxId, todo) => Math.max(todo.id, maxId), -1) + 1,
  9. title: action.text,
  10. completed: false,
  11. }
  12. return { todos: [...state.todos, newTodo] }
  13. }
  14. case REMOVE_TODO: {
  15. return { todos: state.todos.filter(todo => todo.id !== action.id) }
  16. }
  17. default: return state
  18. }
  19. }
Add Comment
Please, Sign In to add comment