Skip to content

Instantly share code, notes, and snippets.

@charlag
Created September 10, 2017 10:19
Show Gist options
  • Save charlag/3b66bf4212bfdcb0e961a8bd609c248e to your computer and use it in GitHub Desktop.
Save charlag/3b66bf4212bfdcb0e961a8bd609c248e to your computer and use it in GitHub Desktop.
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