An open API service indexing awesome lists of open source software.

https://github.com/writetome51/abstract-big-dataset-paginator

An abstract TypeScript/JavaScript class for pagination where all the data to be paginated can't be loaded in memory at once
https://github.com/writetome51/abstract-big-dataset-paginator

application controller javascript paginate pagination typescript

Last synced: 8 months ago
JSON representation

An abstract TypeScript/JavaScript class for pagination where all the data to be paginated can't be loaded in memory at once

Awesome Lists containing this project

README

          

# AbstractBigDatasetPaginator

An abstract TypeScript/Javascript class intended for pagination where all the data
to be paginated can't be loaded in memory at once. Instead of only requesting one
page of data at-a-time from the data source, the paginator has the option of
requesting multiple pages of data to make requests more efficient. You configure
this with the functions `setItemsPerPage()` and `setItemsPerLoad()`. (A load is
either the total number of items you want the app to have in memory at once, or
the total number of items your data source is willing to give you at once ––
whichever is less.)

A subclass must pass a `__setup()` function to this class' constructor (`__setup()`
becomes a private method to give it access to this class' private properties). The only
requirement for `__setup()` is the properties `__pageInfo`, `__loadInfo`, and
`__loadedPage` must be assigned values inside it.

## Constructor

view constructor

```ts
constructor(
__setup: (...args) => void,
setupArgs? = []
)
```

## Private Properties you must know about

view properties

```ts
// These 3 properties must be assigned values inside 'this.__setup()'
// (see constructor).

__pageInfo: {
setItemsPerPage: (num) => void;
getItemsPerPage: () => number;
getTotalPages: () => number;
}

__loadInfo: {
setItemsPerLoad: (num) => void;
getItemsPerLoad: () => number;
}

__loadedPage: {
get: () => any[];
set: (pageNumber) => Promise;

// 'reset' must reload page data from the source
reset: (pageNumber) => Promise;
getNumber: () => number;
}
```

## Methods

view methods

```ts
setItemsPerLoad(num): void

getItemsPerLoad(): number

setItemsPerPage(num): void

getItemsPerPage(): number

getTotalPages(): number

setCurrentPageNumber(num, option? = {reload: false}): Promise
// Set 'option.reload' to true if page data must be reloaded from the source

getCurrentPageNumber(): number

getCurrentPage(): any[]

```

## Installation

`npm i @writetome51/abstract-big-dataset-paginator`

## Loading
```js
import { AbstractBigDatasetPaginator } from '@writetome51/abstract-big-dataset-paginator';
```

## License
[MIT](https://choosealicense.com/licenses/mit/)