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
sindrenm
10/07/2024, 8:27 AM
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
dave08
10/07/2024, 1:02 PM
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
sindrenm
10/07/2024, 2:38 PM
Would there be a different request made to your data source when changing the filters?
sindrenm
10/07/2024, 2:39 PM
If you were to do the filtering locally, then wouldn't you fetch more data than needed?
d
dave08
10/07/2024, 2:42 PM
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
sindrenm
10/07/2024, 4:41 PM
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.