Skip to content

Instantly share code, notes, and snippets.

@JoseAlcerreca
Created May 11, 2021 11:15
Show Gist options
  • Save JoseAlcerreca/a233e3b02e21e021417a596a4a442f95 to your computer and use it in GitHub Desktop.
Save JoseAlcerreca/a233e3b02e21e021417a596a4a442f95 to your computer and use it in GitHub Desktop.
Migrating from LiveData to Kotlin's Flow
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class MyViewModel {
private val _myUiState = MutableLiveData<Result<UiState>>(Result.Loading)
val myUiState: LiveData<Result<UiState>> = _myUiState
// Load data from a suspend fun and mutate state
init {
viewModelScope.launch {
val result = ...
_myUiState.value = result
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment