Best approach for Pager and pagination #608
Replies: 9 comments 4 replies
-
Thanks for starting this discussion. Can you take a look at these changes to |
Beta Was this translation helpful? Give feedback.
-
The main concern regarding using Pager just as a source of and as flows is the point that in real applications the pagination logic should be more complex. For example, it should be able to handle errors in the context of the operation where this error occurred and should distinguish between errors in loading from the cache, and from remote for the initial loading and for the next page loading. Also, it should handle cases like "the next page is empty" to avoid extra requests on scrolling or even show a different UI for this case. This means that this logic should be anyway present somewhere. I am not sure if the Store library is the correct way to place this logic. But I see some parts of it in the RealPager. For example, it is already merging data after loading the next page and serving that data as a whole piece. If there is another stateful component that will handle all that logic that I mentioned above it will in the best case duplicate some parts of the Pager and in the worst case will require a different implementation of the Pager to have access to the raw data that came from the Store. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure I'm following - Can you please clarify what functionality is missing and requires code duplication? If you could share sample code that would be helpful |
Beta Was this translation helpful? Give feedback.
-
I've shared an example of the state machine I am talking about in this gist: https://gist.github.com/electrolobzik/8976a32c31b79ff638e4d7ad6c10eb34. Please do not judge strictly, it is a draft and has not been tested yet. But it should give the idea. The state of the Paginator is later mapped to the UI state and rendered (in my case reactively with Compose). |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing. It's not clear to me what requires code duplication - Re proposal to create a single stateful component - I'd be concerned about combining this with |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I would propose to add "Full" as another possible action of the PagerState. That state means that the previous loading more was successful, but returned empty page, meaning that there is no more data to load. The Pager should not try to load more from this state. Also I would propose adding a separate state "InitialLoadingError" like the existing "ErrorLoadingMore". |
Beta Was this translation helpful? Give feedback.
-
@electrolobzik Added a README |
Beta Was this translation helpful? Give feedback.
-
@electrolobzik - Let's move further discussion to #611. Please feel free to leave comments and questions there |
Beta Was this translation helpful? Give feedback.
-
In my app, I had to implement a state machine for pagination, which uses MutableStore and Pager under the hood. From my point of view Pager and this state machine have an intersection in responsibility, so maybe the best approach would be to implement a single stateful component replacing the current Pager and giving the functionality of error handling and state management.
Beta Was this translation helpful? Give feedback.
All reactions