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

@pineapplelab/paging

v2.0.12

Published

Paging over firebase or data

Downloads

114

Readme

Paging over firebase collections or data array.

Set up:

npm i @pineapplelab/paging

Don't Import PagingModule into your angular project,

If you want run the paging over firestore be sure of call setFirestoreInstance( afs: AngularFirestore )

Example:

@NgModule({
  declarations: [],
  imports: [
    ...
    AngularFireModule.initializeApp(environment.firebase),
    AngularFirestoreModule,
    ...
  ],
  exports: [
    ...
  ]
})
export class CoreModule {
  constructor ( private afs: AngularFirestore ) {
    PagingModule.setFirestoreInstance(afs);
  }
}

API

Default values:

    action = null;
    collection;
    keyField = 'id';
    loading = false;
    orderBy: string = 'name';
    orderDataType = EnumDataType.string;
    orderType = EnumOrderType.asc;
    pagingKey = null;
    preconditions = []
    response = { data: [], hasMore: false, hasLess: false };
    search = '';
    size = this.sizeOptions[0];
    subCollections = [];

Properties:

action: PagingAction; this describe if the paging must change the page on the next loadData() call.

collection: string; this is the collection where the paging run in firestore.

keyField: string; this is the key property in the docs of the current collection, by default is the filed: 'id'.

loading: boolean; this let you know when the paging is loading data.

orderBy: string; The paging will order the result by this field, if it is undefined, empty or null the result will be order by the keyField property.

orderDataType: PagingDataType; this describe the current data type of the orderBy property, by default is string, but if you want order by number or date you must specify it.

orderType: PagingOrderType; this if the order is ascendent or descendent.

pagingKey: string; you must set a paging key if you want for any propose you want.

preconditions: { fieldPath: string | FieldPath, filterOp: WhereFilterOp, value: any }[]; this is used for filter the data, fieldPath must be the property name that you want filter, filterOp must define the how will filter the data, and value is the what will be compared.

response: IPagingResponse<T>; this object has the result data.

search: string; this is for what the paging will be filter.

size: number; this is the size of the current page.

subCollections: { collection: string, docKey: string }[] this is used for run the paging over a sub-collection no matter how deep is it.

mapElements: (element: any, index: number, array: any[]) => T; this can be used for map every row in the result data.

Utilization examples:

  export const PAGING = new Paging<Assessments>( <Paging.IPaging>{
    collection: `assessments`,
    keyField: 'id',
    orderBy: 'name',
    orderType: Paging.orderType.asc,
    mapElements: doc => new Assessments(doc)
  } );
  
  await PAGING.loadData();

Extensions

There are 2 available extended Paging class:

ProgressivePaging:

  • A progressive paging allows to load data from the beginning to the end of the collection.
  • You only need to call the loadMore() method when you see the end of the current list.

LocalPaging:

  • A local paging will get all firebase documents that meet the defined preconditions and sort it in memory.
  • If you want use your own data, call the setLocalData method.