Skip to content

Instantly share code, notes, and snippets.

@dandvl
Last active March 18, 2021 16:59
Show Gist options
  • Save dandvl/0e45872ed71bbb5f8f441804413314d3 to your computer and use it in GitHub Desktop.
Save dandvl/0e45872ed71bbb5f8f441804413314d3 to your computer and use it in GitHub Desktop.
class MyViewModel {
val result = liveData {
emit(doComputation)
}
}
//implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0"
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