Last active
March 18, 2021 16:59
-
-
Save dandvl/0e45872ed71bbb5f8f441804413314d3 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 MyViewModel { | |
val result = liveData { | |
emit(doComputation) | |
} | |
} | |
//implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0" |
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 MyViewModel : ViewModel { | |
private val _result = MutableLiveData<String>() | |
val result = LiveData<String> = _result | |
init { | |
viewModelScope.launch{ | |
val computationResult = doComputation() | |
_result.value = comptationResult | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment