Skip to content

Instantly share code, notes, and snippets.

@kyle-ssg
Created November 27, 2016 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyle-ssg/5c78e9af511773848a2d934b267c43c5 to your computer and use it in GitHub Desktop.
Save kyle-ssg/5c78e9af511773848a2d934b267c43c5 to your computer and use it in GitHub Desktop.
Firebase paging
var loadMore = (ref, from, qty, reverse=false)=> {
var direction = reverse ? 'endAt' : 'startAt';
return ref['direction'](null,from)
.limitToFirst(qty+1)
.once('value')
.then((snap)=>{
var items = snap.val() || {};
var res = {hasMore:false, items};
delete items[from];
res.hasMore = Object.keys(items).length == qty;
return res
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment