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

Option to get plain paginated records directly #1

Open
nicolas-fricke opened this issue Mar 19, 2021 · 0 comments
Open

Option to get plain paginated records directly #1

nicolas-fricke opened this issue Mar 19, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@nicolas-fricke
Copy link
Member

In some cases, we might want to access the paginated records directly and not just have the resulting hash object. Right now, to be able to access these, we would have to first get our paginated result:

posts = Post.all
pagination_result = RailsCursrorPagination::Paginator.new(first: first).fetch

and then access the actual records via

paginated_posts = pagination_result[:page].pluck(:data)

This feels quite cumbersome just to access the paginated data.

Furthermore, it might also be nice to actually interface with objects rather than just having a Hash returned by the #fetch action.

Right now, all the gem's logic is mainly in one big God Class, our RailsCursorPagination::Paginator. So we could use this as an opportunity to also refactor this a bit. However, what's important is that we still want to be able to call

render json: pagination_result

and get the proper JSON response rendered.

So whatever #fetch returns, it should respond to #to_json and return the expected string. But we could do this while still having #fetch return something like a PaginationResult object which then returns a list of PaginationItems when calling #page on it. And each item could return its record when calling #data and could return something like a Cursor instance when #cursor is invoked. And ultimately, the PaginationResult could then have a method #records that collects all the Active Record instances from the individual PaginationItems.

This way, we could split the logic about what cursors are and how they work, what the actual page is and how it's transformed to a hash / to JSON into more self-contained blocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant