Skip to content

Instantly share code, notes, and snippets.

@linean
Created April 13, 2022 17:19
Show Gist options
  • Save linean/737ed4adda726b15e11549d03628877b to your computer and use it in GitHub Desktop.
Save linean/737ed4adda726b15e11549d03628877b to your computer and use it in GitHub Desktop.
class ViewModel {
val state = StateReducerFlow(
initialState = State(),
reduceState = ::reduceState
)
private fun reduceState(currentState: State, event: Event): State {
return when (event) {
is Increment -> currentState.copy(counter = currentState.counter + 1)
is Decrement -> currentState.copy(counter = currentState.counter - 1)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment