Skip to content

Commit

Permalink
fix(todos): eliminate input mutation from the reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkonovalov committed Jan 14, 2018
1 parent 66af8b4 commit 7869cb0
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/app/examples/todos/todos.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,11 @@ export function todosReducer(state = initialState, action: TodosActions) {
});

case TodosActionTypes.TOGGLE:
state.items.some((item: Todo) => {
if (item.id === action.payload.id) {
item.done = !item.done;
return true;
}
});
return Object.assign({}, state, {
items: [...state.items]
items: state.items.map(
(item: Todo) =>
item.id === action.payload.id ? { ...item, done: !item.done } : item
)
});

case TodosActionTypes.REMOVE_DONE:
Expand Down

0 comments on commit 7869cb0

Please sign in to comment.