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

Changes to the .pagination API #1215

Closed
1 task done
PopGoesTheWza opened this issue May 2, 2020 · 9 comments · Fixed by #1644
Closed
1 task done

Changes to the .pagination API #1215

PopGoesTheWza opened this issue May 2, 2020 · 9 comments · Fixed by #1644
Labels
breaking API changes / behavior changes enhancement This change will extend Got features ✭ help wanted ✭
Milestone

Comments

@PopGoesTheWza
Copy link
Contributor

What problem are you trying to solve?

Improve .pagination API (and possibly performance and stability)

Describe the feature

I would humbly suggest the following 2 breaking changes:

  • Switch order of allItems and currentItems parameters of pagination.paginate, pagination.filter and pagination.shouldContinue

My reasoning about parameters order is that probably most use cases don't need the allItems parameters, with currentItems typically being more used. To be confirmed by other users, but if indeed currentItems is used more than allItems then it should reflect in the order of parameters.

It doesn't change how the Got code works but could save custom pagination.paginate, pagination.filter and pagination.shouldContinue from having an unused and unaesthetic _ as the second parameter... ;)

  • Default value for stackAllItem to false

As per the default of allItems, it implies a waste of CPU and RAM resources when unused. This is especially noticeable when iterating large datasets (and can results in a node.js crash in worst case scenarios)

Checklist

  • I have read the documentation and made sure this feature doesn't already exist.
@szmarczak szmarczak added the question The issue is a question about Got label May 2, 2020
@szmarczak
Copy link
Collaborator

szmarczak commented May 2, 2020

unaesthetic _ as the second parameter...

You can use a rule that only forces you to have _ only at the beginning, so you can have _allItems. I cannot decide on this on either.

Regarding the stackAllItems option, it mainly depends on what most people do. We need more feedback.

@fiznool
Copy link
Contributor

fiznool commented May 2, 2020

FWIW, when there is more than one value to be passed in to a function I prefer to pass in an object so it can be destructured. This permits the access of any/all of the properties in the object and also allows further properties to be easily added at a later date.

So the full signature for pagination.paginate would resemble:

paginate({ response, allItems, currentItem })

If you only wanted currentItem:

paginate({ currentItem })

@PopGoesTheWza
Copy link
Contributor Author

I too usually prefer object parameters when possible/sensible. I don't think it is common with callback signatures, though...

@szmarczak
Copy link
Collaborator

@fiznool Good idea. We already did this with retry.calculateDelay.

@PopGoesTheWza
Copy link
Contributor Author

This brought me into checking this.

@sindresorhus sindresorhus added this to the Got v12 milestone May 3, 2020
@sindresorhus
Copy link
Owner

I agree. We should make it an object instead in Got v12 (not soon, unfortunately).

@sindresorhus
Copy link
Owner

As for:

Default value for stackAllItem to false

I haven't yet made up my mind. If you use the pagination API, please chime in on this.

@sindresorhus
Copy link
Owner

If anyone wants to see this happen in Got 12, now would be a time to submit a pull request, otherwise, we'll defer it to Got 13.

@sindresorhus sindresorhus added breaking API changes / behavior changes enhancement This change will extend Got features ✭ help wanted ✭ and removed question The issue is a question about Got labels Feb 24, 2021
@PopGoesTheWza
Copy link
Contributor Author

@szmarczak sorry for the late PRs. Looks like they won't be needed after all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking API changes / behavior changes enhancement This change will extend Got features ✭ help wanted ✭
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants