Skip to content

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

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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