mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
23 lines
428 B
JavaScript
23 lines
428 B
JavaScript
const todos = (state = [], action) => {
|
|
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
|
|
}
|
|
}
|
|
|
|
export default todos
|