Lit-element: Adding reflectToAttribute to the demo doesn't work

Created on 21 Jan 2018  路  7Comments  路  Source: Polymer/lit-element

      static get properties() {
        return {
          foo: String,
          bar: Number,
          whales: { type: Number, reflectToAttribute: true }
        }
      }
whales: 馃惓馃惓馃惓馃惓馃惓馃惓馃惓

$0.whales
7
$0.getAttribute("whales")
"0"

Most helpful comment

Where in a heaven are these documented? I was breaking my head :(

All 7 comments

I think in the Polymer.PropertiesMixin only types are supported.

Maybe, that is why I didn't examine further. It would be nice to know whether these features are going to be deprecated or just not implemented yet.

Default values also don't seem to be supported e.g.

foo: {
  type: String,
  value: "bar",
}

This is by design. With LitElement we explicitly wanted to make "properties" less powerful and more straightforward.

Property defaults should be set in the standard way, in the constructor. This is generally better for performance.

We also elected not to support observers or reflectToAttribute from PolymerElement instead preferring users to write this pretty standard code explicitly.

Where in a heaven are these documented? I was breaking my head :(

We also elected not to support observers or reflectToAttribute from PolymerElement instead preferring users to write this pretty standard code explicitly.

Code samples showing how implement those would be helpful

@blikblum Here's how you can implement basic reflection (proof of concept, won't work with inherited properties)

    _shouldRender(props, changedProps, prevProps) {
        Object.keys(changedProps)
            .filter(property => this.constructor.properties[property].reflectToAttribute)
            .forEach(property =>
                this._propertyToAttribute(
                    property,
                    this.constructor.attributeNameForProperty(property),
                    changedProps[property]
                )
            )
        return super._shouldRender(props, changedProps, prevProps)
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

aadamsx picture aadamsx  路  3Comments

chrismbeckett picture chrismbeckett  路  3Comments

sorvell picture sorvell  路  3Comments

Leon-Alexey picture Leon-Alexey  路  5Comments

tamis-laan picture tamis-laan  路  4Comments