-
-
Save skydoves/c365fa25cad148eff5716190242a3ada to your computer and use it in GitHub Desktop.
OnetimeWhileSubscribed_sample
This file contains 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
val pokemon = savedStateHandle.getStateFlow<Pokemon?>("pokemon", null) | |
val pokemonInfo: StateFlow<PokemonInfo?> = | |
pokemon.filterNotNull().flatMapLatest { pokemon -> | |
detailsRepository.fetchPokemonInfo(pokemon.id) | |
}.stateIn( | |
scope = viewModelScope, | |
started = OnetimeWhileSubscribed(5_000), | |
initialValue = null, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment