Never Publish Malarkey

    This package has been deprecated

    Author message:

    Use @writetome51/get-page-batch instead

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

    3.0.0 • Public • Published

    BatchLoader

    A TypeScript/Javascript class that loads a batch (array) of data from a larger set
    that is too big to be loaded all at once. This batch can then be used by a
    paginator or any other kind of manipulation tool.

    Constructor

    view constructor
    constructor(
        // These objects are injected because most likely they'll have to be used
        // outside this class as well.
    
        dataSource: {
        
            getBatch: (batchNumber: number, itemsPerBatch: number, isLastBatch: boolean) => any[];
                // `getBatch()` is called whenever a new batch must be loaded.  The number of items it 
                // returns matches `itemsPerBatch`.  If `isLastBatch` is true, it only returns the 
                // remaining items in the dataset, and ignores itemsPerBatch.
    
            dataTotal: number;
                // Number of items in entire dataset, not the batch.
                // This must stay accurate after actions that change the total, such as searches.
        },
    
        batchContainer: { data: any[] },
            
        batchInfo: {
            // This provides `dataSource` with info on what batch to get, how many items, etc.
            
            itemsPerBatch: number;
            currentBatchNumber: number;
            currentBatchNumberIsLast: boolean;
            pagesPerBatch: number;
        },
    
        bch2pgTranslator: BatchToPageTranslator
            // Included as a dependency.
            // https://www.npmjs.com/package/@writetome51/batch-to-page-translator
    ) 

    Methods

    view methods
    loadBatch(batchNumber): void
        // Gets the batch and stores it in `batchContainer.data` (from the 
        // constructor).
    
    loadBatchContainingPage(pageNumber): void
        // Useful if you intend to use the batch for pagination.
        // Gets the batch containing `pageNumber` and stores it in `batchContainer.data`

    Installation

    npm i @writetome51/batch-loader

    Loading

    // if using TypeScript:
    import { BatchLoader } from '@writetome51/batch-loader';
    // if using ES5 JavaScript:
    var BatchLoader = require('@writetome51/batch-loader').BatchLoader;

    License

    MIT

    Install

    npm i @writetome51/batch-loader

    DownloadsWeekly Downloads

    3

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    12.6 kB

    Total Files

    7

    Last publish

    Collaborators

    • npm