Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface TodoAction {
- type: string;
- todo: TodoImmutable;
- todoList: List<TodoImmutable>; // On ajoute le paramètre 'todoList'
- }
- export const todoReducer = (state: List<TodoImmutable> = fromJS([]), action: TodoAction) => {
- switch (action.type) {
- case Action.GET_ALL_TODOS: // On retourne simplement la nouvelle liste de todos
- return action.todoList;
- case Action.ADD_TODO:
- return state.push(action.todo);
- case Action.UPDATE_TODO:
- return state.set(
- state.findIndex((todo: TodoImmutable) => todo.get('_id') === action.todo.get('_id')),
- action.todo
- );
- case Action.REMOVE_TODO:
- return state.remove(
- state.findIndex((todo: TodoImmutable) => todo.get('_id') === action.todo.get('_id'))
- );
- default:
- return state;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement