Skip to content

Commit 8b3e0cb

Browse files
dankoknadtimdorr
authored andcommitted
syncing docs with recent PR (2431) (#2432)
1 parent e238a19 commit 8b3e0cb

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

docs/basics/ExampleTodoList.md

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,38 +58,22 @@ export const toggleTodo = id => {
5858
#### `reducers/todos.js`
5959

6060
```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-
8361
const todos = (state = [], action) => {
8462
switch (action.type) {
8563
case 'ADD_TODO':
8664
return [
87-
...state,
88-
todo(undefined, action)
65+
...state,
66+
{
67+
id: action.id,
68+
text: action.text,
69+
completed: false
70+
}
8971
]
9072
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
9377
)
9478
default:
9579
return state

0 commit comments

Comments
 (0)