Skip to content

Instantly share code, notes, and snippets.

@JoseAlcerreca
Created June 25, 2020 15:07
Show Gist options
  • Save JoseAlcerreca/8a5488ee8b1abc539261431256ccff69 to your computer and use it in GitHub Desktop.
Save JoseAlcerreca/8a5488ee8b1abc539261431256ccff69 to your computer and use it in GitHub Desktop.
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
// Don't do this. Use liveData instead.
class MyViewModel : ViewModel() {
private val _result = MutableLiveData<String>()
val result: LiveData<String> = _result
init {
viewModelScope.launch {
val computationResult = doComputation()
_result.value = computationResult
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment