mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
24 lines
450 B
JavaScript
24 lines
450 B
JavaScript
|
|
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
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export default todos
|