useo-pl / jsom-pagination

A JSON:API pagination support
MIT License
22 stars 7 forks source link

Add `JSOM::Pagination::Import` to allow injecting dependencies using dry-system #2

Open swilgosz opened 4 years ago

swilgosz commented 4 years ago

Currently, to get the paginator, we need to instantiate the object in the index class.

paginator = JSOM::Pagination::Paginator.new
paginated = paginator.call(collection, params: { number: 2, size: 3 }, base_ur: 'https://example.com')

It would be nice to instantiate it once during the application boot and allow to reuse the same object whenever it's needed. We could use dry-system for that:

include JSOM::Pagination::Import['paginator']

paginated = paginator.call(collection, params: { number: 2, size: 3 }, base_ur: 'https://example.com')