Created
May 11, 2021 11:15
-
-
Save JoseAlcerreca/a233e3b02e21e021417a596a4a442f95 to your computer and use it in GitHub Desktop.
Migrating from LiveData to Kotlin's Flow
This file contains hidden or 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 --> | |
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