Fixing the complete reducer to actually create new instance of a todo item

This commit is contained in:
Ken
2019-02-28 09:23:27 -08:00
parent 5e5717240c
commit 2105301c83
8 changed files with 51 additions and 31 deletions

View File

@@ -13,10 +13,9 @@ export function remove(state: Store['todos'], id: string) {
}
export function complete(state: Store['todos'], id: string) {
const newTodos = { ...state };
newTodos[id].completed = !newTodos[id].completed;
return newTodos;
// Clone the todo, overriding
const newTodo = { ...state[id], completed: !state[id].completed };
return { ...state, [id]: newTodo };
}
export function clear(state: Store['todos']) {

View File

@@ -13,10 +13,9 @@ export function remove(state: Store['todos'], id: string) {
}
export function complete(state: Store['todos'], id: string) {
const newTodos = { ...state };
newTodos[id].completed = !newTodos[id].completed;
return newTodos;
// Clone the todo, overriding
const newTodo = { ...state[id], completed: !state[id].completed };
return { ...state, [id]: newTodo };
}
export function clear(state: Store['todos']) {