Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Update accepted types for simple observer #2404

Closed
TimvdLippe opened this issue Dec 1, 2017 · 2 comments
Closed

Update accepted types for simple observer #2404

TimvdLippe opened this issue Dec 1, 2017 · 2 comments

Comments

@TimvdLippe
Copy link
Contributor

In Polymer/polymer#4574 we updated the accepted values of observer for properties to also accept a function. The documentation of https://www.polymer-project.org/2.0/docs/devguide/properties should be updated to reflect this change.

@ghost
Copy link

ghost commented Jan 10, 2018

@arthurevans what example/s do you think we should show for referring to a function directly?

Option 1: Refer to prototype? (shown in Polymer/polymer#4543)

class XCustom extends Polymer.Element {
  static get is() {return 'x-custom'; }
  static get properties() {
    return {
      active: {
        type: Boolean,
        observer: XCustom.prototype._activeChanged
      }
    }
  }
  _activeChanged(newValue, oldValue) {
    this.toggleClass('highlight', newValue);
  }
}

Example 2: this.methodName?

class XCustom extends Polymer.Element {
  static get is() {return 'x-custom'; }
  static get properties() {
    return {
      active: {
        type: Boolean,
        observer: this._activeChanged.bind(this)
      }
    }
  }
  _activeChanged(newValue, oldValue) {
    this.toggleClass('highlight', newValue);
  }
}

Example 3: Anonymous function?

class XCustom extends Polymer.Element {
  static get is() {return 'x-custom'; }
  static get properties() {
    return {
      active: {
        type: Boolean,
        observer: function (newValue, oldValue) {
          this.toggleClass('highlight', newValue);
        }.bind(this)
      }
    }
  }
}

@TimvdLippe
Copy link
Contributor Author

TimvdLippe commented Jan 10, 2018 via email

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant