-
-
Notifications
You must be signed in to change notification settings - Fork 957
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
Pass allItems
and currentItems
to _pagination.paginate()
#1100
Conversation
You can do that in a |
No, I do not duplicate the Think about this scenario: |
I don't get it. Why don't just modify the offset in |
But that would trigger an unnecessary request wouldn't it? If the last response contains only 10 of 20 items, it would anyway try another time with an updated offset. |
Oh, I get you now! :D |
allItems
and currentItems
to _pagination.paginate()
Co-Authored-By: Szymon Marczak <36894700+szmarczak@users.noreply.github.com>
Co-Authored-By: Szymon Marczak <36894700+szmarczak@users.noreply.github.com>
Sorry, maybe I was not clear enough before 😊 |
You have nothing to be sorry for, that's the point of a conversation - to make things clear :D |
Co-Authored-By: Szymon Marczak <36894700+szmarczak@users.noreply.github.com>
Co-Authored-By: Szymon Marczak <36894700+szmarczak@users.noreply.github.com>
Don't forget to update the docs :) |
Here we go 😊 |
Good idea. I just added the example to the paginate function part. |
readme.md
Outdated
@@ -680,25 +680,27 @@ A function that transform [`Response`](#response) into an array of items. This i | |||
###### \_pagination.paginate | |||
|
|||
Type: `Function`\ | |||
Default: [`Link` header logic](source/index.ts) | |||
Default: `(response, allItems, currentItems) => getLinkFromHeaders(response)` (find details [here](source/index.ts)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I restored it but changed the sentence afterwards to make clear how the signature of the function should be. This should make it easier for users without diving into the code first.
readme.md
Outdated
|
||
A function that returns an object representing Got options pointing to the next page. If there are no more pages, `false` should be returned. | ||
|
||
For example, if you want to stop when the response contains less items that expected, you should use `(response, allItems, currentItems) => currentItems.length < LIMIT ? false : { url: getNextLink(response, allItems, currentItems) }`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the LIMIT
should be a response.request.options.searchParams.entriesPerPage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that expected
-> than expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, it's updated.
tests are failing somehow |
I think the issue with the tests is independently since it first arose after documentation changes. Also, it also fails for Node 13 only... |
Thanks for pushing it forward! 😊 |
readme.md
Outdated
For example, if you want to stop when the response contains less items than expected, you can use something like this: | ||
|
||
```js | ||
(response, allItems, currentItems) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer the example to be fully runnable, meaning that it includes the import statement and got(…)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just extended the example.
Sometimes you need
alltems
or the items from the last response in thepaginate
function (e.g. to compare if current length of items are less than requested size).Checklist