-
-
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
Change the stackAllItems
option to be false
by default
#1645
Changes from all commits
2e2dd37
e0b9af2
d8e62d7
027e70d
f395998
ca5d464
683693e
3dfeb22
ec97764
01acfbf
4366927
3cda939
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,14 @@ export type ResponseType = 'json' | 'buffer' | 'text'; | |
|
||
export interface PaginateData<BodyType, ElementType> { | ||
response: Response<BodyType>; | ||
allItems: ElementType[]; | ||
currentItems: ElementType[]; | ||
allItems: ElementType[]; | ||
} | ||
|
||
export interface FilterData<ElementType> { | ||
item: ElementType; | ||
allItems: ElementType[]; | ||
currentItems: ElementType[]; | ||
allItems: ElementType[]; | ||
} | ||
|
||
export interface PaginationOptions<ElementType, BodyType> { | ||
|
@@ -39,15 +39,15 @@ export interface PaginationOptions<ElementType, BodyType> { | |
/** | ||
Checks whether the item should be emitted or not. | ||
|
||
@default ({item, allItems, currentItems}) => true | ||
@default ({item, currentItems, allItems}) => true | ||
*/ | ||
filter?: (data: FilterData<ElementType>) => boolean; | ||
|
||
/** | ||
The function takes an object with the following properties: | ||
- `response` - The current response object. | ||
- `allItems` - An array of the emitted items. | ||
- `currentItems` - Items from the current response. | ||
- `allItems` - An empty array, unless when `pagination.stackAllItems` is set to `true`. In the later case, an array of the emitted items. | ||
|
||
It should return an object representing Got options pointing to the next page. | ||
The options are merged automatically with the previous request, therefore the options returned `pagination.paginate(...)` must reflect changes only. | ||
|
@@ -66,7 +66,7 @@ export interface PaginationOptions<ElementType, BodyType> { | |
offset: 0 | ||
}, | ||
pagination: { | ||
paginate: (response, allItems, currentItems) => { | ||
paginate: ({response, currentItems}) => { | ||
const previousSearchParams = response.request.options.searchParams; | ||
const previousOffset = previousSearchParams.get('offset'); | ||
|
||
|
@@ -98,7 +98,7 @@ export interface PaginationOptions<ElementType, BodyType> { | |
If you want to stop **after** emitting the entry, you should use | ||
`({item, allItems}) => allItems.some(item => item.flag)` instead. | ||
|
||
@default ({item, allItems, currentItems}) => true | ||
@default ({item, currentItems, allItems}) => true | ||
*/ | ||
shouldContinue?: (data: FilterData<ElementType>) => boolean; | ||
|
||
|
@@ -126,10 +126,11 @@ export interface PaginationOptions<ElementType, BodyType> { | |
requestLimit?: number; | ||
|
||
/** | ||
Defines how the parameter `allItems` in pagination.paginate, pagination.filter and pagination.shouldContinue is managed. | ||
When set to `false`, the parameter `allItems` is always an empty array. | ||
Defines how the property `allItems` in pagination.paginate, pagination.filter and pagination.shouldContinue is managed. | ||
|
||
By default, the property `allItems` is always an empty array. This setting can be helpful to save on memory usage when working with a large dataset. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @szmarczak Don't forget to keep the TS docs in sync. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah sorry, overlooked this one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed: 4cce4de There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, currently I'm not home. I'll be back tomorrow. |
||
|
||
This option can be helpful to save on memory usage when working with a large dataset. | ||
When set to `true`, the property `allItems` is an array of the emitted items. | ||
*/ | ||
stackAllItems?: boolean; | ||
}; | ||
|
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.
@PopGoesTheWza You forgot to keep the TS docs in sync.