You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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
renderjson: 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.
The text was updated successfully, but these errors were encountered:
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:
and then access the actual records via
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 calland 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 aPaginationResult
object which then returns a list ofPaginationItem
s when calling#page
on it. And each item could return its record when calling#data
and could return something like aCursor
instance when#cursor
is invoked. And ultimately, thePaginationResult
could then have a method#records
that collects all the Active Record instances from the individualPaginationItem
s.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.
The text was updated successfully, but these errors were encountered: