Last active
May 29, 2019 08:56
-
-
Save lucanicoletti/0f3721e218302ddfdae2f3c390214f2b 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 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