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/ed81e251b95f40ea8ac659f36857f0af to your computer and use it in GitHub Desktop.
Save GuilhE/ed81e251b95f40ea8ac659f36857f0af to your computer and use it in GitHub Desktop.
Medium articles - MVI+FSM
class TimerViewModel : ViewModel() {
private val _state = MutableLiveData<TimerUiState>(TimerUiState())
val state: LiveData<TimerUiState> = _state
fun settingTime() {
_state.value = state.value.copy(isSettingTimer = true, isCountingDown = false, isRestarting = false)
}
fun setTime(seconds: Int) {
_state.value = TimerUiState(seconds)
}
}
//Observing state changes in the View
@Composable
fun TimerScreen(viewModel: TimerViewModel) {
with(viewModel.state.observeAsState().value) { /*...*/ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment