Giter VIP home page Giter VIP logo

Comments (7)

tiagopog avatar tiagopog commented on May 30, 2024

Hey there, @austenito! As you pointed, JSONAPI::Utils still doesn't support neither custom paginators nor pagination strategy per resource; as well as there's a lack of support for cursor-based pagination strategy.

Now I'm implementing a better support for custom filters and I will probably do some refactoring on JSONAPI::Utils::Support::Pagination, since the code there is same from the first POCs that I made for the gem.

It would be really great to see a PR implementing those features for pagination πŸ‘

from jsonapi-utils.

austenito avatar austenito commented on May 30, 2024

@tiagopog I'll give it a shot!

Also, I believe cursor pagination was removed cerebris/jsonapi-resources#301

from jsonapi-utils.

tiagopog avatar tiagopog commented on May 30, 2024

Indeed it was removed in JR, but since there's a growing adoption of some databases with cursor-based pagination (e.g. Google Cloud Datastore) it would be nice to bring a paginator that supports it.

You could start by implementing the support for custom paginator and later we could think on a proper way to deal with cursos.

from jsonapi-utils.

tiagopog avatar tiagopog commented on May 30, 2024

πŸ‘€ #27

from jsonapi-utils.

tiagopog avatar tiagopog commented on May 30, 2024

Just took a free time tonight to refactor the module JSONAPI::Utils::Support::Pagination. Hope it helps you.

from jsonapi-utils.

austenito avatar austenito commented on May 30, 2024

@tiagopog nice refactor :)

One of the things I've been thinking about is how to handle the pagination via ranges since custom paginators handle ranges differently. For example:

def pagination_range
  case JSONAPI.configuration.default_paginator
  when :paged
    number = page_params['number'].to_i.nonzero? || 1
    size   = page_params['size'].to_i.nonzero?   || JSONAPI.configuration.default_page_size
    (number - 1) * size..number * size - 1
  when :offset
    offset = page_params['offset'].to_i.nonzero? || 0
    limit  = page_params['limit'].to_i.nonzero?  || JSONAPI.configuration.default_page_size
    offset..offset + limit - 1
  end
end

I was thinking about delegating to each paginator to return the appropriate range. Anyways, I hope to get a branch up soon for you πŸ‘€ at :)

from jsonapi-utils.

tiagopog avatar tiagopog commented on May 30, 2024

Delegate this kinda job to paginators would be the ideal scenario, the thing is: JSONAPI::Resources doesn't support rendering Array of Hashes – the use case where range is used for pagination – then we should open the default paginator classes or stuff to add this behavior. I'm avoiding to monkey patch things as much as I can, so that I prefered to write this method rather than changing a few objects at runtime.

Thanks for the coming PR, I'm sure it will be awesome! Cheers!

from jsonapi-utils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.