File tree Expand file tree Collapse file tree 1 file changed +10
-26
lines changed Expand file tree Collapse file tree 1 file changed +10
-26
lines changed Original file line number Diff line number Diff line change @@ -58,38 +58,22 @@ export const toggleTodo = id => {
58
58
#### ` reducers/todos.js `
59
59
60
60
``` js
61
- const todo = (state = {}, action ) => {
62
- switch (action .type ) {
63
- case ' ADD_TODO' :
64
- return {
65
- id: action .id ,
66
- text: action .text ,
67
- completed: false
68
- }
69
- case ' TOGGLE_TODO' :
70
- if (state .id !== action .id ) {
71
- return state
72
- }
73
-
74
- return Object .assign ({}, state, {
75
- completed: ! state .completed
76
- })
77
-
78
- default :
79
- return state
80
- }
81
- }
82
-
83
61
const todos = (state = [], action ) => {
84
62
switch (action .type ) {
85
63
case ' ADD_TODO' :
86
64
return [
87
- ... state,
88
- todo (undefined , action)
65
+ ... state,
66
+ {
67
+ id: action .id ,
68
+ text: action .text ,
69
+ completed: false
70
+ }
89
71
]
90
72
case ' TOGGLE_TODO' :
91
- return state .map (t =>
92
- todo (t, action)
73
+ return state .map (todo =>
74
+ (todo .id === action .id )
75
+ ? {... todo, completed: ! todo .completed }
76
+ : todo
93
77
)
94
78
default :
95
79
return state
You can’t perform that action at this time.
0 commit comments