Skip to content

Instantly share code, notes, and snippets.

@lucanicoletti
Last active May 29, 2019 08:56
Show Gist options
  • Save lucanicoletti/0f3721e218302ddfdae2f3c390214f2b to your computer and use it in GitHub Desktop.
Save lucanicoletti/0f3721e218302ddfdae2f3c390214f2b to your computer and use it in GitHub Desktop.
class MVIViewModel : ViewModel() {
val viewState: MutableLiveData<MVIViewState>()
fun fetchData() {
myDataSource.fetchData()
.doOnSubscribe {
viewState.postValue(MVIViewState.Loading)
}
.observe(
{
viewState.postValue(MVIViewState.Success(it.result))
},
{
viewState.postValue(MVIViewState.Error(it.reason))
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment