-
-
Save GuilhE/ed81e251b95f40ea8ac659f36857f0af 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() { | |
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