npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@writetome51/abstract-app-paginator

v1.0.0

Published

An abstract TypeScript/JavaScript pagination class

Downloads

1

Readme

AbstractAppPaginator

An abstract TypeScript/Javascript class intended for pagination in a
real-world web app. Though it is a class, most of its implementation
does not exist as-is. A subclass must be made, which provides a
dataSource and __setup() function to this class' constructor.
__setup() becomes a class method and must accept dataSource
as a parameter, but as for what dataSource is and what __setup()
does, that is up to the subclass. The only requirement this class
makes is __setup() must assign values to the properties __pageInfo,
__batchInfo, and __pageLoader, so the code in this class will
execute properly.

It's possible to use this class for 'batchination', where, instead of
only requesting one page of data at-a-time from the server, the client
requests a bigger 'batch', the size of which is determined by the
property itemsPerBatch. Then the batch is paginated in the client. If
the user requests a page that would be found in a different batch, the
client requests that batch from the server and paginates it. And so on.

Constructor

constructor(
    dataSource,
    private __setup: (dataSource) => void
)

Properties

itemsPerBatch: number
    // Total number of items the app can have loaded in memory.  Set this to 
    // highest number that does not negatively affect app performance.

itemsPerPage: number

currentPageNumber: number // read-only

currentPage: any[] // read-only
    // All items in the current page.

totalPages: number // read-only

Private Properties you must know about

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

__pageInfo: { itemsPerPage: number, totalPages: number }

__batchInfo: { itemsPerBatch: number }

__pageLoader: {

    loadPage: (pageNumber) => Promise<void>,

    forceLoadPage: (pageNumber) => Promise<void>,
        // Must load `pageNumber` all over again, even if that page is already 
        // currently loaded.

    loadedPage: any[]
        // All items in the loaded page.
}

Methods

async set_currentPageNumber(num): Promise<void>
    // updates this.currentPage

async resetToFirstPage() : Promise<void>
    // force-loads page 1.
    // Intended to be called after the order of the dataset changes (like 
    // after sorting), or after the total number of items changes (like after 
    // a search).

Installation

npm i @writetome51/abstract-app-paginator

Loading

// if using TypeScript:
import { AbstractAppPaginator } from '@writetome51/abstract-app-paginator';
// if using ES5 JavaScript:
var AbstractAppPaginator = 
    require('@writetome51/abstract-app-paginator').AbstractAppPaginator;

License

MIT