Do we have some thing similar to switch map for mu...
# compose
c
Do we have some thing similar to switch map for mutable state flow . I want to trigger network calls only some values changes ?
s
c
It is not serving my purpose, flatMapLatest calls every time when I come back to list fragment from detail fragment although there is no value change in _requestParams
Copy code
val pendingReviewList: Flow<PagingData<PendingReview>> =
    _requestParams.flatMapLatest {
        Timber.i("Current value : $it")
        providerRepository.getPendingReviewList(limit = 10).cachedIn(viewModelScope)
    }
but this is not happening in case Mutable live data
Copy code
val posts = _requestParams.switchMap {
    repository.getGuestPostedReviews().cachedIn(viewModelScope).asLiveData()
}
I fixed this with below code
Copy code
private val _refreshCall = MutableLiveData<Boolean>(false)


    val pendingReviewList: Flow<PagingData<PendingReview>> =
        _refreshCall.switchMap {
            providerRepository.getPendingReviewList(limit = 10).cachedIn(viewModelScope)
                .asLiveData()
        }.asFlow()


    fun refresh() {
        _refreshCall.value?.let {
            _refreshCall.value = !it
        }
    }