Created
June 25, 2022 20:11
-
-
Save alibahaaa/744e12450519614f2ecb39236eb5914e to your computer and use it in GitHub Desktop.
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 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