Skip to content

Instantly share code, notes, and snippets.

@alibahaaa
Created June 25, 2022 20:11
Show Gist options
  • Save alibahaaa/744e12450519614f2ecb39236eb5914e to your computer and use it in GitHub Desktop.
Save alibahaaa/744e12450519614f2ecb39236eb5914e to your computer and use it in GitHub Desktop.
class MainViewModel(
private val getOrigamiUseCase: GetOrigamiUseCase
) : BaseViewModel<Intent,State>() {
override fun createInitialState(): State = State.Idle
override fun handleIntent(intent: Intent) {
when(intent){
Intent.FetchOrigamiData -> getOrigami()
}
}
private fun getOrigami() = viewModelScope.launch {
setState { State.Loading }
val res = getOrigamiUseCase.invoke()
if (res.isEmpty())
setState { State.Error }
else
setState { State.Origami(res) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment