Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
bizboard-firebase-paginator
Advanced tools
The original had bugs and/or insufficiently document usage scenarios, so we (Bizboard) forked it for our purposes.
FirebasePaginator is a JavaScript utility for Node.js and the browser that enables simple, declarative pagination for your Firebase collections. It's been developed for Firebase 3.0, but it should work for Firebase 2.0 projects as well.
FirebasePaginator relies on the Promise object. Promise support is great for modern versions of Chrome, Firefox, Edge, Opera and Safari. Internet Explorer gets left out. Sorry IE, but even Microsoft is sick of you. You're dying. And attempting to support you would only prolong the misery.
FirebasePaginator uses the Axios library for Node.js and XMLHttpRequest in the browser.
In summary: Node.js requires Promise and Axios; the browser requires Promise and XMLHttpRequest.
npm install --save firebase-paginator
bower install --save firebase-paginator
npm install
npm test
If you're in Node.js, you'll need to do something like var FirebasePaginator = require('firebase-paginator')
.
If you're in the browser, you'll have access to FirebasePaginator on the window
object like so: var FirebasePaginator = window.FirebasePaginator;
Once you have your FirebasePaginator
object, the rest is isomorphic JavaScript. Just pass in a Firebase ref and some options:
pageSize: any integer greater than zero, defaults to 10
finite: defaults to false
auth: optional auth token for secure collections
var options = {
pageSize: 15,
finite: true,
auth: 'MyAuthTokenForSecurityPurposes'
};
var paginator = new FirebasePaginator(ref, options);
Listens to all events
Useful for proxying events or just debugging
var paginator = new FirebasePaginator(ref);
var itemsList = [];
paginator.listen(function (eventName, eventPayload) {
console(`Fired ${eventName} with the following payload: `, eventPayload);
});
Attaches a callback to an event
var paginator = new FirebasePaginator(ref);
var itemsList = [];
var handler = function() {
collection = paginator.collection;
};
paginator.on('value', handler);
Detaches a callback from an event
var paginator = new FirebasePaginator(ref);
var itemsList = [];
var handler = function() {
collection = paginator.collection;
};
paginator.off('value', handler);
Calls a callback exactly once for an event
var paginator = new FirebasePaginator(ref);
var itemsList = [];
var handler = function() {
collection = paginator.collection;
};
// Callback pattern
paginator.once('value', handler);
// Promise pattern
paginator.once('value').then(handler);
Resets pagination
Infinite: jumps to end of collection
Finite: Refreshes keys list and jumps to page 1
var paginator = new FirebasePaginator(ref);
paginator.reset()
.then(function() {
console.log('list has been reset');
});
Pages backward
var paginator = new FirebasePaginator(ref);
paginator.previous()
.then(function() {
console.log('paginated backward');
});
Pages forward
var paginator = new FirebasePaginator(ref);
paginator.next()
.then(function() {
console.log('paginated forward');
});
Jumps to any page
Accepts page numbers from 1 to the pageCount
Available for finite pagination only
var paginator = new FirebasePaginator(ref);
paginator.goToPage(3)
.then(function() {
console.log('paginated to page 3');
});
The value event fires after every change in data. FirebasePaginator listens to the Firebase value event, manipulates the data a bit and then fires its own value event.
isLastPage fires just after the value event if FirebasePaginator has reached the top of the list.
FirebasePaginator fires its ready event once the first page is loaded.
The reset, next and previous events fire after each of the corresponding functions is complete and the new data is loaded.
There are two ways to paginate Firebase data: finite and infinite paginations.
Let's assume that pageSize is 10 and we have records 1 through 100. Also note that all Firebase pagination occurs from the bottom of the collection.
Infinite pagination pulls the last 11 records of the collection, saves the 90th record's key as a cursor and adds records 91 through 100 to the collection.
Infinite pagination steps backward by pulling another 11 records ending at the cursor (a.k.a. the 90th record's key). So paging back once will display records 81 to 90 with record 80's key as the new cursor. Page back again and you're at records 71 to 80 and so forth.
Pros:
Cons:
Finite pagination makes a single "shallow" REST query to pull all of the collection's keys. See the docs on how this is done.
Once FirebasePaginator has all of the keys, it sorts them and finds the page endpoints. So if we have 100 records with a pageSize of 10, the page endpoints will be the keys for records 10, 20, 30, 40, 50... 100.
Pros:
Cons:
paginator.reset()
to capture new records the may be addedFAQs
For of the original Firebase Paginator
The npm package bizboard-firebase-paginator receives a total of 4 weekly downloads. As such, bizboard-firebase-paginator popularity was classified as not popular.
We found that bizboard-firebase-paginator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.