What's the difference between refresh and source.refresh in CombinedLoadStates?

198 Views Asked by At

If there is not remoteMediator, does this mean that refresh is the same to source.refresh?

It looks consistent from the logs, can someone give me an affirmative answer?

onCreateView: source.Refresh=NotLoading(endOfPaginationReached=false)
onCreateView: source.Append=Loading(endOfPaginationReached=false)
onCreateView: source.Prepend=NotLoading(endOfPaginationReached=true)
onCreateView: Prepend=NotLoading(endOfPaginationReached=true)
onCreateView: Refresh=NotLoading(endOfPaginationReached=false)
onCreateView: Append=Loading(endOfPaginationReached=false)
onCreateView: source.Refresh=NotLoading(endOfPaginationReached=false)
onCreateView: source.Append=NotLoading(endOfPaginationReached=false)
onCreateView: source.Prepend=NotLoading(endOfPaginationReached=true)
onCreateView: Prepend=NotLoading(endOfPaginationReached=true)
onCreateView: Refresh=NotLoading(endOfPaginationReached=false)
onCreateView: Append=NotLoading(endOfPaginationReached=false)
1

There are 1 best solutions below

0
Michael On

I have found the answer, which is consistent with my conjecture.

private fun computeHelperState(
    previousState: LoadState,
    sourceRefreshState: LoadState,
    sourceState: LoadState,
    remoteState: LoadState?
): LoadState {
    
    if (remoteState == null) return sourceState // if the remoteState is null, return sourceState directly.
    
    return when (previousState) {
        is Loading -> when {
            sourceRefreshState is NotLoading && remoteState is NotLoading -> remoteState
            remoteState is Error -> remoteState
            else -> previousState
        }
        else -> remoteState
    }
}