Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Plaid - ShotViewModel
class ShotViewModel(...) {
init {
val result = shotsRepository.getShot(shotId)
if (result is Result.Success) {
// FIRST UI EMISSION with an incomplete UI Model
_shotUiModel.value = result.data.toShotUiModel()
processUiModel(result.data)
} else { ... }
}
private fun processUiModel(shot: Shot) {
viewModelScope.launch(dispatcherProvider.main) {
// Processing full model in the background
// The createShotUseCase makes this call main-safe
val uiModel = createShotUiModel(shot)
// SECOND UI EMISSION with the full UI Model
_shotUiModel.value = uiModel
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.