Advertisement
cbigot

Untitled

Feb 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. interface TodoAction {
  2.     type: string;
  3.     todo: TodoImmutable;
  4.     todoList: List<TodoImmutable>; // On ajoute le paramètre 'todoList'
  5. }
  6.  
  7. export const todoReducer = (state: List<TodoImmutable> = fromJS([]), action: TodoAction) => {
  8.     switch (action.type) {
  9.         case Action.GET_ALL_TODOS: // On retourne simplement la nouvelle liste de todos
  10.             return action.todoList;
  11.         case Action.ADD_TODO:
  12.             return state.push(action.todo);
  13.         case Action.UPDATE_TODO:
  14.             return state.set(
  15.                 state.findIndex((todo: TodoImmutable) => todo.get('_id') === action.todo.get('_id')),
  16.                 action.todo
  17.             );
  18.         case Action.REMOVE_TODO:
  19.             return state.remove(
  20.                 state.findIndex((todo: TodoImmutable) => todo.get('_id') === action.todo.get('_id'))
  21.             );
  22.         default:
  23.             return state;
  24.     }
  25. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement