Last active
          May 31, 2019 17:22 
        
      - 
      
- 
        Save lucanicoletti/d72da121d9f6d748828fc9af8d309391 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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 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