return case (action) { when {type: 'set-visibility-filter', filter: visFilter} -> ({...state, visFilter}), when {type: 'add-todo', text} -> ({...state, todos: [...state.todos, {text}]}), when {type: 'toggle-todo', index} -> ( { ...state, todos: state.todos.map((todo, idx) => idx === index ? {...todo, done: !todo.done} : todo ) } ) when _ -> state // ignore unknown actions } } 5