Skip to content

<propertyName>Changed may get called twice for a single property value change #298

@frankiefu

Description

@frankiefu

When you run the below code you will see x-bar's valueChanged() is being called twice. Debugging shows that in instance/properties.js, this._observeNames has ["value", "value"], and that causing it to register 2 observers on the same property. I believe the root cause is in declaration/properties.js, optimizePropertyMaps() simply concats base's observeNames and this observeNames, and doesn't remove duplicates.
https://github.com/Polymer/polymer/blob/master/src/declaration/properties.js#L25

<polymer-element name="x-foo" attributes="value">
  <script>
    Polymer('x-foo', {
      value: null,
      valueChanged: function() {
      }
    });
  </script>
</polymer-element>

<polymer-element name="x-bar" extends="x-foo">
  <script>
    Polymer('x-bar', {
      valueChanged: function() {
        console.log('x-bar valueChanged:', this.value);
      }
    });
  </script>
</polymer-element>

<x-bar></x-bar>

<script>
  document.addEventListener('WebComponentsReady', function() {
    document.querySelector('x-bar').value = {};
  });
</script>

output:

x-bar valueChanged: Object {}
x-bar valueChanged: Object {} 

p.s. This issue is only happening in master branch.

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