File tree Expand file tree Collapse file tree 1 file changed +9
-25
lines changed
examples/todos/src/reducers Expand file tree Collapse file tree 1 file changed +9
-25
lines changed Original file line number Diff line number Diff line change 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
-
23
1
const todos = ( state = [ ] , action ) => {
24
2
switch ( action . type ) {
25
3
case 'ADD_TODO' :
26
4
return [
27
5
...state ,
28
- todo ( undefined , action )
6
+ {
7
+ id : action . id ,
8
+ text : action . text ,
9
+ completed : false
10
+ }
29
11
]
30
12
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
33
17
)
34
18
default :
35
19
return state
You can’t perform that action at this time.
0 commit comments