googlearchive / firebase-util

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

Firebase.util.Scroll not taking '$value' and '$key' as arguments #62

Closed lf-alves closed 9 years ago

lf-alves commented 9 years ago

Hello,

I decided to test the code provided on the firebase-util's pagination docs

var baseRef = new Firebase('https://fbutil.firebaseio.com/paginate'); var scrollRef = new Firebase.util.Scroll(baseRef, '$key'); // special scroll methods are namespaced in scrollRef.scroll scrollRef.scroll.next(25);

And it throws this error when you run it:

Error: Firebase (2.2.3) INTERNAL ASSERT FAILED: Unrecognized index type!

Really weird error because if you pass in any other string as the orderBy field parameter, it runs smoothly. I tried passing in '$key' and '$value' and it breaks every time.

I think that the Scroll function is issuing a orderByChild query every time you pass in a string as a parameter. For example, if you pass in '$value', it throws this error: Error: Query.orderByChild: "$value" is invalid. Use Query.orderByValue() instead.

Curiously enough, if you pass in '$priority' nothing happens.

katowulf commented 9 years ago

This doesn't seem possible, since Scroll calls Cache, which calls Offset. And here's the code in Offset processing the ref and field specified: https://github.com/firebase/firebase-util/blob/master/src/Paginate/libs/Offset.js#L228

Can you try this with 0.2.5? If that causes the error, an actual stack trace and a repro would be useful.

lf-alves commented 9 years ago

Yep, that fixed it! Thanks. Didn't know 0.2.5 was out. Digging into it a little bit more, I found out that my firebase-util.js file had this:

function baseRef(ref, field) { if( field === '$key' ) { return ref.orderByKey(); } else if( field === '$priority' ) { return ref.orderByPriority(); } else { return ref.orderByChild(field); } }

It was lacking the else if from field === '$value'. I don't know why. I installed it with bower and it was all perfectly included in my project. (version 0.2.4). Thanks, Kato.