Todo List

The source code for all examples can be found on Github.

Another classic example.

Coverage

  • Model
  • Actions
  • Actions with Payload
const model = {
input: '',
todos: [],
}
const actions = {
setInput: (state, input) => [
{
...state,
input,
},
],
addTodo: (state, text) => [
{
...state,
input: '',
todos: [
...state.todos,
{
text,
checked: false,
},
],
},
],
toggleTodo: (state, id) => [
{
...state,
todos: state.todos.map((todo, index) => {
if (index === id) {
return {
...todo,
checked: !todo.checked,
}
}
return todo
}),
},
],
removeTodo: (state, id) => [
{
...state,
todos: [...state.todos.slice(0, id), ...state.todos.slice(id + 1)],
},
],
}
Crafted with ♡ by Robin Weser