@writetome51/current-page
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

CurrentPage

A TypeScript/Javascript class intended to help a separate Paginator
paginate data that can't all be stored in memory at once.

Instantiation

// Use this factory function:

getInstance_CurrentPage(
    params: {
        dataSource: {

            // If `isLastLoad` is true, it must only return the remaining items in the dataset and
            // ignore `itemsPerLoad`.

            getLoad: (
                loadNumber: number, itemsPerLoad: number, isLastLoad: boolean
            ) => Promise<any[]>;
        };

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

        loadInfo: {
            getCurrentLoadNumber: () => number;
            setCurrentLoadNumber: (num) => void;
            getItemsPerLoad: () => number;
            currentLoadIsLast: () => boolean;
            getPagesPerLoad: () => number;
        };
    }
): CurrentPage

Methods

view methods
set(pageNumber): Promise<void>
    // After calling this, get the page's data by calling this.get().

reset(pageNumber): Promise<void>
    // Even if `pageNumber` is already the current page, the 
    // data containing that page is reloaded from the source.

get(): any[]
    // returns the contents of the page.

Installation

npm i @writetome51/current-page

Loading

import { CurrentPage, getInstance_CurrentPage } from '@writetome51/current-page';

License

MIT

Package Sidebar

Install

npm i @writetome51/current-page

Weekly Downloads

5

Version

2.0.1

License

MIT

Unpacked Size

12 kB

Total Files

11

Last publish

Collaborators

  • writetome51