Skip to content

Instantly share code, notes, and snippets.

@JoseAlcerreca
Last active May 17, 2021 14:18
Show Gist options
  • Save JoseAlcerreca/b60c6ee56267d3d32ede34fe313077a0 to your computer and use it in GitHub Desktop.
Save JoseAlcerreca/b60c6ee56267d3d32ede34fe313077a0 to your computer and use it in GitHub Desktop.
val result = userId.transformLatest { newUserId ->
emit(Result.LoadingData)
emit(repository.fetchItem(newUserId))
}.stateIn(
scope = viewModelScope,
started = WhileSubscribed(5000),
initialValue = Result.LoadingUser // Note the different Loading states
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment