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
- Host: GitHub
- URL: https://github.com/writetome51/abstract-big-dataset-paginator
- Owner: writetome51
- License: mit
- Created: 2019-01-30T07:13:33.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-10T18:46:00.000Z (over 4 years ago)
- Last Synced: 2025-02-02T08:16:35.755Z (9 months ago)
- Topics: application, controller, javascript, paginate, pagination, typescript
- Language: TypeScript
- Homepage:
- Size: 120 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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): voidgetItemsPerLoad(): 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 sourcegetCurrentPageNumber(): 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/)