mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-14 05:14:28 -08:00
finish redux example
This commit is contained in:
@@ -1,22 +1,21 @@
|
||||
const todos = (state = [], action) => {
|
||||
switch (action.type) {
|
||||
case 'ADD_TODO':
|
||||
return [
|
||||
...state,
|
||||
{
|
||||
id: action.id,
|
||||
text: action.text,
|
||||
completed: false
|
||||
}
|
||||
]
|
||||
case 'TOGGLE_TODO':
|
||||
return state.map(todo =>
|
||||
(todo.id === action.id)
|
||||
? {...todo, completed: !todo.completed}
|
||||
: todo
|
||||
)
|
||||
default:
|
||||
return state
|
||||
if(action.type == 'ADD_TODO') {
|
||||
return [
|
||||
...state,
|
||||
{
|
||||
id: action.id,
|
||||
text: action.text,
|
||||
completed: false
|
||||
}
|
||||
]
|
||||
} else if(action.type == 'TOGGLE_TODO') {
|
||||
return state.map(todo =>
|
||||
(todo.id === action.id)
|
||||
? {...todo, completed: !todo.completed}
|
||||
: todo
|
||||
)
|
||||
} else {
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user