icerockdev / moko-paging

Pagination logic in common code for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
59 stars 7 forks source link

Incorrect state value when setData(emptyList()) #33

Closed denmusic1992 closed 3 years ago

denmusic1992 commented 3 years ago

I'm trying to set a new data to pagination when clearing items. When items list is empty, I need to set pagination state = Empty But it's not working as I expected. There are setDataSuspend and asStateNullIsEmpty methods:

suspend fun setDataSuspend(items: List<Item>?) {
        listMutex.lock()
        mStateStorage.value = items.asStateNullIsEmpty()
        mEndOfList.value = false
        listMutex.unlock()
    }

fun <T, E> T?.asStateNullIsEmpty() = asState {
    ResourceState.Loading<T, E>()
}

It would be great when passing emptyList to pagination we will get an Empty Resource State in it.