Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Add mergeMode to simplePagination helper #1173

Closed
hoangvvo opened this issue Nov 19, 2020 · 0 comments · Fixed by #1174
Closed

RFC: Add mergeMode to simplePagination helper #1173

hoangvvo opened this issue Nov 19, 2020 · 0 comments · Fixed by #1174
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release

Comments

@hoangvvo
Copy link
Contributor

hoangvvo commented Nov 19, 2020

Summary

Relay Pagination allows setting mergeMode to define how the paginated items are merged. From the doc:

Example series of requests:

first: 1 => node 1, endCursor: a
first: 1, after: 1 => node 2, endCursor: b
...
last: 1 => node 99, startCursor: c
last: 1, before: c => node 89, startCursor: d

With inwards merging the nodes will be in this order: [1, 2, ..., 89, 99] And with outwards merging: [..., 89, 99, 1, 2, ...]

We should implement a similar feature in Simple Pagination.

A use case is for the infinite scroll that needs to load previous items when scrolling up, where the pages with higher skip or offset value should be inserted to the beginning of the array. Ex: Chat app. In this case, later paginated items should be added to the beginning instead of the end.

Proposed Solution

Add a new option mergeMode = "before" | "after" to define how pages will be merged. If mergeMode = "after" (default), (later) pages with higher offset will be added after the others. This matches the current behavior so it will not be a breaking change. Otherwise, if mergeMode = "before", (later) pages with higher offset will be added before the others.

Example:

Where mergeMode = "after" (default) makes sense:

offset = 0 => 1,2,3
offset = 3 => 4,5,6
mergeMode = "after" => [1,2,3,  4,5,6]
mergeMode = "before" => [4,5,6,  1,2,3]

Where mergeMode = "before" makes sense:

offset = 0 => 4,5,6
offset = 3 => 1,2,3
mergeMode = "after" => [4,5,6,  1,2,3]
mergeMode = "before" => [1,2,3,  4,5,6]

Here is a demo image (source):
image

@hoangvvo hoangvvo added the future 🔮 An enhancement or feature proposal that will be addressed after the next release label Nov 19, 2020
@hoangvvo hoangvvo changed the title RFC: [Simple Pagination] Add mergeMode RFC: Add mergeMode to simplePagination helper Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant