Skip to content

Commit e238a19

Browse files
dankoknadtimdorr
authored andcommitted
'todo' const removal from reducers/todos.js (#2431)
1 parent 0babfab commit e238a19

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

examples/todos/src/reducers/todos.js

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,19 @@
1-
const todo = (state, action) => {
2-
switch (action.type) {
3-
case 'ADD_TODO':
4-
return {
5-
id: action.id,
6-
text: action.text,
7-
completed: false
8-
}
9-
case 'TOGGLE_TODO':
10-
if (state.id !== action.id) {
11-
return state
12-
}
13-
14-
return {
15-
...state,
16-
completed: !state.completed
17-
}
18-
default:
19-
return state
20-
}
21-
}
22-
231
const todos = (state = [], action) => {
242
switch (action.type) {
253
case 'ADD_TODO':
264
return [
275
...state,
28-
todo(undefined, action)
6+
{
7+
id: action.id,
8+
text: action.text,
9+
completed: false
10+
}
2911
]
3012
case 'TOGGLE_TODO':
31-
return state.map(t =>
32-
todo(t, action)
13+
return state.map(todo =>
14+
(todo.id === action.id)
15+
? {...todo, completed: !todo.completed}
16+
: todo
3317
)
3418
default:
3519
return state

0 commit comments

Comments
 (0)