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

Change the stackAllItems option to be false by default #1645

Merged
merged 12 commits into from
Feb 26, 2021
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ Default: [`Link` header logic](source/index.ts)

The function takes an object with the following properties:
- `response` - The current response object.
- `allItems` - An array of the emitted items.
- `allItems` - An array of the emitted items if [pagination.stackAllItems](#pagination.stackAllItems) is set to `true`. An empty array otherwise.
PopGoesTheWza marked this conversation as resolved.
Show resolved Hide resolved
- `currentItems` - Items from the current response.

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. If there are no more pages, `false` should be returned.
Expand Down Expand Up @@ -1022,11 +1022,11 @@ For example, it can be helpful during development to avoid an infinite number of
###### pagination.stackAllItems

Type: `boolean`\
Default: `true`
Default: `false`

Defines how the parameter `allItems` in [pagination.paginate](#pagination.paginate), [pagination.filter](#pagination.filter) and [pagination.shouldContinue](#pagination.shouldContinue) is managed. When set to `false`, the parameter `allItems` is always an empty array.
Defines how the parameter `allItems` in [pagination.paginate](#pagination.paginate), [pagination.filter](#pagination.filter) and [pagination.shouldContinue](#pagination.shouldContinue) is managed. When set to `true`, the parameter `allItems` is an of the emitted items.

This option can be helpful to save on memory usage when working with a large dataset.
When set to `false`, the parameter `allItems` is always an empty array. This option can be helpful to save on memory usage when working with a large dataset.

##### localAddress

Expand Down
6 changes: 3 additions & 3 deletions source/as-promise/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface PaginationOptions<ElementType, BodyType> {
/**
The function takes an object with the following properties:
- `response` - The current response object.
- `allItems` - An array of the emitted items.
- `allItems` - An array of the emitted items if `pagination.stackAllItems` is set to `true`. An empty array otherwise.
- `currentItems` - Items from the current response.

It should return an object representing Got options pointing to the next page.
Expand Down Expand Up @@ -127,9 +127,9 @@ export interface PaginationOptions<ElementType, BodyType> {

/**
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.
When set to `true`, the parameter `allItems` is an of the emitted items.
PopGoesTheWza marked this conversation as resolved.
Show resolved Hide resolved

This option can be helpful to save on memory usage when working with a large dataset.
When set to `false`, the parameter `allItems` is always an empty array. This option can be helpful to save on memory usage when working with a large dataset.
*/
stackAllItems?: boolean;
};
Expand Down
2 changes: 1 addition & 1 deletion source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const defaults: InstanceDefaults = {
countLimit: Number.POSITIVE_INFINITY,
backoff: 0,
requestLimit: 10000,
stackAllItems: true
stackAllItems: false
},
parseJson: (text: string) => JSON.parse(text),
stringifyJson: (object: unknown) => JSON.stringify(object),
Expand Down