Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class MVIJetpackComposeViewModel : ViewModel() {
private val _jetpackComposeViewState = MutableLiveData<MVIJetpackComposeViewState>()
private val useCase = UseCase()
val jetpackComposeViewState: LiveData<MVIJetpackComposeViewState>
get() = _jetpackComposeViewState
init {
loadData()
}
fun loadData() {
// fetch data from wherever you want
useCase.loadData()
.doOnSubscribe {
_jetpackComposeViewState.postValue(MyViewState.Loading)
}
.observe(
{ response ->
_jetpackComposeViewState.postValue(MyViewState.Success(response.title))
},
{ error ->
_jetpackComposeViewState.postValue(
MyViewState.Error(error.reason, ::loadData)
)
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.