Remon Shehata
09/27/2023, 11:47 AMSharedFlow, collectLatest and debounce so the endpoint won't be hit every time there is a text change.
However, collectLatest is being called many times. why? and how can I fix it?
full code
searchText
.debounce(1000)
.distinctUntilChanged { prev, next -> prev != next }
.filter { it.isNotEmpty() }
.sample(500)
.collectLatest {
Log.d("Remon", "search collect - value: $it")
}Damian Baczyński
09/27/2023, 12:43 PMdistinctUntilChanged has valid check? This lambda should check for elements equality and your current implementation does the opposite.Remon Shehata
09/27/2023, 12:49 PMRemon Shehata
09/27/2023, 12:49 PMprev == next ... same result..Damian Baczyński
09/27/2023, 1:10 PMsearchText
.debounce(1000)
.distinctUntilChanged()
.filter { it.isNotEmpty() }
.collectLatest {
Log.d("Remon", "search collect - value: $it")
}Remon Shehata
09/27/2023, 1:40 PMDamian Baczyński
09/27/2023, 1:47 PMRemon Shehata
09/27/2023, 1:48 PMRemon Shehata
09/27/2023, 1:48 PMDamian Baczyński
09/27/2023, 1:49 PM