Odinakachukwu Omaka-chukwu
01/17/2025, 3:09 PMval dataUiState: StateFlow<UiState<Data>> = queryFlow
.debounce(300)
.mapLatest {
// How to set state to UiState.Loading while request is still running
// Get new data based on filter
val data = requestData(it)
UiState.Success(data)
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), UiState.Loading)
I would like to reset the state to UiState.Loading
while the data request is still fetching.Zach Klippenstein (he/him) [MOD]
01/17/2025, 3:12 PMmapLatest
you could use flatMapLatest
and make a flow that starts with loading, or probably simpler to just use transformLatest
and emit loading before emitting the load result.streetsofboston
01/17/2025, 3:14 PMOdinakachukwu Omaka-chukwu
01/17/2025, 4:16 PMtransformLatest
was exactly what I needed