Skip to content

Instantly share code, notes, and snippets.

@manuelvicnt
Created October 9, 2019 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelvicnt/c4c3564c33b981ca2091b3f24a77c5a9 to your computer and use it in GitHub Desktop.
Save manuelvicnt/c4c3564c33b981ca2091b3f24a77c5a9 to your computer and use it in GitHub Desktop.
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