let state = {
todos: [
{ id: 1, text: 'foo' },
{ id: 2, text: 'foo' },
],
//...
}
function updateTodo(state, { id, text }) {
return Object.assign({}, state, {
todos: state.todos.map(todo => {
if (todo.id === id) {
return Object.assign({}, todo, { text });
}
else {
return todo;
}
}),
});
}