Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.
This repository was archived by the owner on May 19, 2025. It is now read-only.

Polymer 2.0-Preview, polymer-query returns duplicated rows. #170

@mwinters-stuff

Description

@mwinters-stuff

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);
      }
    },

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions