Firebase Richer Query Capabilities for firebase-element

196 views
Skip to first unread message

Chuck Horton

unread,
Nov 5, 2014, 8:03:43 AM11/5/14
to polym...@googlegroups.com
Does the firebase-element support the new Firebase Richer Query Capabilities or does it need to be updated? See https://www.firebase.com/blog/2014-11-04-firebase-realtime-queries.html for announcement.

var ref = new Firebase("https://dinosaur-facts.firebaseio.com/");
ref.orderByChild("height").on("child_added", function(snapshot) {
  console
.log(snapshot.key() + " was " + snapshot.val().height + " meters tall");
});

var ref = new Firebase("https://dinosaur-facts.firebaseio.com/");
ref.orderByChild("height").startAt(3).on("child_added", function(snapshot) {
  console
.log(snapshot.key())
});

Eric Bidelman

unread,
Nov 5, 2014, 12:56:01 PM11/5/14
to Chuck Horton, polymer-dev

Hey Chuck, the fb element is very basic and doesn't support a lot of firebase's awesome. PRs or new elements to that repo are welcome :)

Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/7a560412-09a6-4957-930c-5a95ae9cf2b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chuck Horton

unread,
Nov 5, 2014, 5:30:37 PM11/5/14
to polym...@googlegroups.com, ch...@hware.com
I will give it a try. Any suggestions or tips to help me get started adding the new functionality to firebase-element. I have already forked the firebase-element.

Found the following in the Firebase 2.0.0 chang log:

FEATURE Added Query.orderByChild() for ordering by arbitrary child attributes.
FEATURE Added Query.orderByKey() and Query.orderByPriority() to explicitly set sort order.
FEATURE Added Query.equalTo() for exact-match filtering using arbitrary child attributes.
FEATURE Added Query.limitToFirst() and Query.limitToLast() to explicitly set limit direction.
FEATURE Improved performance of existing query functionality.
CHANGED Changes in priority now raise a child_changed event in addition to a child_moved event.
DEPRECATED Deprecated Firebase.name() in favor of Firebase.key().
DEPRECATED Deprecated DataSnapshot.name() in favor of DataSnapshot.key().
DEPRECATED Deprecated Query.limit() in favor of Query.limitToFirst() or Query.limitToLast().
REMOVED Removed the previously-deprecated Firebase.setOnDisconnect() and Firebase.removeOnDisconnect() methods.
FIXED Firebase.ServerValue.TIMESTAMP now works properly in transactions.
FIXED Transaction callbacks now always return the snapshot from the specific transaction.
FIXED Fixed transactions bug when running on cached data.
FIXED Fixed some cases where child_added events were raised with only partially-complete data.

Chuck Horton

unread,
Nov 6, 2014, 5:56:31 PM11/6/14
to polym...@googlegroups.com, ch...@hware.com
Hey Eric,

So far in my branch I have Firebase.key(), limitToFirst(), limitToLast(), child_moved working. I have orderByChild, orderByKey, and orderByKey partially working.

When I use my firebase-element:

    <firebase-element id="dinosaurOrderByChild" on-data-change="{{dinosaurOrderByChildDataChange}}" data="{{dinosaurOrderByChildData}}" keys="{{dinosaurOrderByChildKeys}}" orderByChild="order" location="https://dinosaur-facts.firebaseio.com/" log></firebase-element>


The console shows that the child-addd have been sorted ok, but the data stored in dinosaurOrderByChildData is not sorted.

Console log messages:
child-added lambeosaurus firebase-element.html:420
child-added stegosaurus firebase-element.html:420
child-added triceratops firebase-element.html:420
child-added pterodactyl firebase-element.html:420
child-added bruhathkayosaurus firebase-element.html:420
child-added linhenykus firebase-element.html:420
acquired value https://dinosaur-facts.firebaseio.com/ firebase-element.html:321

And the object stored in dinosaurOrderByChildData is not sorted.
{bruhathkayosaurus: Object, lambeosaurus: Object, linhenykus: Object, pterodactyl: Object, stegosaurus: Object…}

Do you have and idea why this is happening?

See full code at:

Requery function
```
requery: function() {
     
// shut-down previous observers (if any)
     
this.closeQuery();
     
this.closeObserver();
     
// construct new query
     
var query = this.ref;
     
if (query) {
       
if (this.start && !this.orderByKey) {
          console
.log("requery: startAt", this.start);
          query
= query.startAt(this.start);
       
}
       
if (this.end) {
          query
= query.endAt(this.end);
       
}
       
if (this.limit > 0) {
          query
= query.limit(this.limit);
       
}
       
if (this.limitToFirst > 0) {
          query
= query.limitToFirst(this.limitToFirst);
       
}
       
if (this.limitToLast > 0) {
          query
= query.limitToLast(this.limitToLast);
       
}
       
if (this.orderByChild) {
          console
.log("requery: orderByChild", this.orderByChild, this.ref);
          query
= query.orderByChild(this.orderByChild);
       
}

       
if (this.orderByKey) {
         
if (this.start) {
            query
= query.orderByKey().startAt(this.start);
         
} else  {
            query
= query.orderByKey();
         
}
         
// console.log("requery: orderByKey", query);
       
}
       
if (this.orderByPriority) {
          console
.log("requery: orderByPriority", this.ref);
          query
= query.orderByPriority();
       
}
       
this.query = query;
       
// console.log("requery: query", this.query)
     
}
   
},


```

On Wednesday, November 5, 2014 9:56:01 AM UTC-8, Eric Bidelman wrote:

Chuck Horton

unread,
Nov 10, 2014, 12:38:31 PM11/10/14
to polym...@googlegroups.com, ch...@hware.com
Hey Eric, I have submit a pull request for this. This is the pull request: https://github.com/Polymer/firebase-element/pull/23.

I also signed the Google Contributor License Agreement.


On Wednesday, November 5, 2014 9:56:01 AM UTC-8, Eric Bidelman wrote:
Reply all
Reply to author
Forward
0 new messages