Description
When using the polymer 2.0 preview, The firebase-query element returns the data array with the data duplicated.
Eg, if the queried data on the server has 7 items, the firebase-query has 14, each item is listed twice.
Expected outcome
You get the 7 items with no duplicates.
Actual outcome
No specific example, just query a path and check the results.
Whats happening.
The __queryChanged is called more than once for the query, which seems to add more than one "child_added" e.t.c. event handlers.
Solve
I solved this by changing __query changed to remove handlers if they were previously registered.
`
__queryChanged: function(query, oldQuery) {
if (oldQuery) {
oldQuery.off('child_added', this.__onFirebaseChildAdded, this);
oldQuery.off('child_removed', this.__onFirebaseChildRemoved, this);
oldQuery.off('child_changed', this.__onFirebaseChildChanged, this);
oldQuery.off('child_moved', this.__onFirebaseChildMoved, this);
this.syncToMemory(function() {
this.set('data', this.zeroValue);
});
}
if (query) {
if(this._onOnce){ // remove handlers before adding again.
query.off('child_added', this.__onFirebaseChildAdded, this);
query.off('child_removed', this.__onFirebaseChildRemoved, this);
query.off('child_changed', this.__onFirebaseChildChanged, this);
query.off('child_moved', this.__onFirebaseChildMoved, this);
}
this._onOnce = true;
query.on('child_added', this.__onFirebaseChildAdded, this.__onError, this);
query.on('child_removed', this.__onFirebaseChildRemoved, this.__onError, this);
query.on('child_changed', this.__onFirebaseChildChanged, this.__onError, this);
query.on('child_moved', this.__onFirebaseChildMoved, this.__onError, this);
}
},
`
Description
When using the polymer 2.0 preview, The firebase-query element returns the data array with the data duplicated.
Eg, if the queried data on the server has 7 items, the firebase-query has 14, each item is listed twice.
Expected outcome
You get the 7 items with no duplicates.
Actual outcome
No specific example, just query a path and check the results.
Whats happening.
The __queryChanged is called more than once for the query, which seems to add more than one "child_added" e.t.c. event handlers.
Solve
I solved this by changing __query changed to remove handlers if they were previously registered.
`
__queryChanged: function(query, oldQuery) {
`