Created
June 25, 2020 15:07
-
-
Save JoseAlcerreca/8a5488ee8b1abc539261431256ccff69 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
<!-- 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