What's the recommended way to work with a UiState ...
# compose-android
d
What's the recommended way to work with a UiState class in a ViewModel and paginated data (using Paging 3 library)? I need to filter that paginated data based on the Chip selected... Is it right to just recreate a Pager for each filter change?
s
Assuming you make a different request to get new results for when the filters change? In that case, it makes sense to me to create a new Pager.
d
So just paginated the same request is the same pager, whereas a new request would be a different one... I guess there's a third possibility though -- to use
filter
on the PagingData itself...
s
Would there be a different request made to your data source when changing the filters?
If you were to do the filtering locally, then wouldn't you fetch more data than needed?
d
I was considering both options... but you're right, in the end I do fetch too much data when filtering locally... it's just that Meilisearch returns more results when filtered than originally found and messes up the counts of results per filter... but that's another subject. What I'm really wondering is why would I have to make a new pager when changing filters on the request side...? I'm having trouble grasping the reasoning behind all this.
s
You might not need to create a new Pager, but you would probably at least need to create a new PagingSource, as the result of whatever the Pager's
pagingSourceFactory
returns. And since I don't know when Pager calls
pagingSourceFactory()
to create new PagingSources internally, it feels more correct to create an entirely new Pager.