-
-
Save GuilhE/686d543497b31cec5f079ca9e86536f8 to your computer and use it in GitHub Desktop.
Medium articles - MVI+FSM
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
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