Created
September 10, 2017 10:19
-
-
Save charlag/3b66bf4212bfdcb0e961a8bd609c248e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun reducer(state: State, event: Event): State = when (event) { | |
is Event.TodoCheckedEvent -> { | |
val todos = state.todos.map { todo -> | |
if (todo.id == event.id) todo.copy(completed = event.completed) | |
else todo | |
} | |
state.copy(todos = todos) | |
} | |
is Event.DbUpdateEvent -> state.copy(todos = event.todos) | |
is Event.NewTodoEvent -> state.copy( | |
todos = state.todos + TodoEntity(0L, event.text, false) | |
) | |
else -> state | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment