Skip to content

Instantly share code, notes, and snippets.

@GuilhE
Last active March 28, 2022 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuilhE/686d543497b31cec5f079ca9e86536f8 to your computer and use it in GitHub Desktop.
Save GuilhE/686d543497b31cec5f079ca9e86536f8 to your computer and use it in GitHub Desktop.
Medium articles - MVI+FSM
class TimerViewModel : ViewModel(), ContainerHost<TimerUiState, Nothing> {
override val container = viewModelScope.container<TimerUiState, Nothing>(TimerUiState())
fun settingTime() {
intent { reduce { state.copy(isSettingTimer = true, isCountingDown = false, isRestarting = false) } }
}
fun setTime(seconds: Int) {
intent { reduce { TimerUiState(seconds) } }
}
}
//Collecting state changes in the View
@Composable
fun TimerScreen(viewModel: TimerViewModel) {
with(viewModel.collectAsState().value) { /*...*/ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment