Created
October 9, 2019 08:53
-
-
Save manuelvicnt/c4c3564c33b981ca2091b3f24a77c5a9 to your computer and use it in GitHub Desktop.
Plaid - ShotViewModel
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
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