googlearchive / firebase-util

An experimental toolset for Firebase
http://firebase.github.io/firebase-util
MIT License
276 stars 67 forks source link

Scroll to last option is required #79

Open vikasprogrammer opened 8 years ago

vikasprogrammer commented 8 years ago

I have a usecase wherein I need to move to the last of the ref initially and then call several prev()s to move back in the list.

Somthing like

scrollRef.scroll.last(25);

Is this possible?

katowulf commented 8 years ago

Sounds like a great addition. PRs welcome.

vikasprogrammer commented 8 years ago

Thanks!

I tried it with the following code and failed miserably, will really appreciate your help here. :

Scroll.prototype.last = function(lastNumRecords, totalRecords) {
  if( this.hasNext() ) {
    this.end = totalRecords;
    this.start = totalRecords - lastNumRecords;
    this.cache.moveTo(this.start, this.end - this.start);
  }
};

I wanted to determine totalRecords on the fly once this code started working. :(

katowulf commented 8 years ago

Sorry, I assumed this was related to Paginate. That's the only context where this makes sense.

Infinite scroll, by definition, should be able to handle an infinite number of records, and thus it won't be able to go to the end of the list or count the number of records. The solution here would be to store an attribute on the records that puts them in descending order, and then use that as the sort field.

vikasprogrammer commented 8 years ago

I have a timestamp field which is added to records as they get added. There is no way to sort records in descending order. Only best thing is to use setWithPriority. Is that right approach?

katowulf commented 8 years ago

Change your timestamp field to a negative value, so they are ordered descending.

vikasprogrammer commented 8 years ago

Yupe, found that solution. Thanks @katowulf

vikasprogrammer commented 8 years ago

PS: I am using negative timestamp in the $priority field.

puf commented 8 years ago

Any reason to not simply store it in a invertedTimestamp field? That way you won't depend on a hidden property.

On Wed, Dec 16, 2015 at 8:31 AM vikasprogrammer notifications@github.com wrote:

PS: I am using negative timestamp in the $priority field.

— Reply to this email directly or view it on GitHub https://github.com/firebase/firebase-util/issues/79#issuecomment-165165470 .

vikasprogrammer commented 8 years ago

No reason, I am just exploring various options. I think your suggestion has a valid point.

PS: @puf This question for the app https://instantchat.io, you liked in the Firebase's Google group.

maneja81 commented 8 years ago

I use this function to set priority for decending order.

function priority(){ var now = new Date().getTime(); return -1 * now; }