Skip to content

Instantly share code, notes, and snippets.

@JoseAlcerreca
Created May 11, 2021 11:21
Show Gist options
  • Save JoseAlcerreca/c72baad8ccdf9ba3b5afd0adf242c6d8 to your computer and use it in GitHub Desktop.
Save JoseAlcerreca/c72baad8ccdf9ba3b5afd0adf242c6d8 to your computer and use it in GitHub Desktop.
class MyViewModel(authManager..., repository...) : ViewModel() {
private val userId: Flow<UserId> = authManager.observeUser().map { user -> user.id }
val result: LiveData<Result<Item>> = userId.mapLatest { newUserId ->
repository.fetchItem(newUserId)
}.asLiveData()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment