Mohamed Ibrahim
10/07/2021, 1:38 PMprivate fun SearchScreenEvent.eventToUsecase(): Flow<SearchState> {
return when (this) {
is SearchClicked -> searchUsecase(this.query)
is SearchQueryChanged ->
flowOf(this.query)
.debounce(5000)
.flatMapConcat { searchUsecase(this.query) }
}
}
why debounce is not working hereMatti MK
10/07/2021, 1:47 PMflow
on every SearchQueryChanged
Mohamed Ibrahim
10/07/2021, 2:09 PMswitchMap
with publish
to resolve this,
here is How I subscribe my events
events
.flatMapConcat { it.eventToUsecase() }
.onEach { _states.value = it }
.launchIn(viewModelScope)
Mohamed Ibrahim
10/07/2021, 2:10 PMephemient
10/07/2021, 4:24 PMephemient
10/07/2021, 4:32 PMephemient
10/07/2021, 4:35 PMmerge(
searchClicks,
searchQueryChanges.debounce(5000L)
)
ephemient
10/07/2021, 4:36 PMMohamed Ibrahim
10/07/2021, 5:25 PM