Skip to content

Instantly share code, notes, and snippets.

@fluxtah
Created February 19, 2020 14:41
Show Gist options
  • Save fluxtah/e7cb5f277caa0fefa0845b84fcbeb878 to your computer and use it in GitHub Desktop.
Save fluxtah/e7cb5f277caa0fefa0845b84fcbeb878 to your computer and use it in GitHub Desktop.
class MyViewModel : BaseViewModel() {
val data: LiveData<String> = MutableLiveData()
fun load() {
data.forceValue("Hello, World")
}
private fun <T> LiveData<T>.forceValue(value: T) {
(this as MutableLiveData<T>).value = value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment