Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding reflectToAttribute to the demo doesn't work #10

Closed
kenchris opened this issue Jan 21, 2018 · 7 comments
Closed

Adding reflectToAttribute to the demo doesn't work #10

kenchris opened this issue Jan 21, 2018 · 7 comments

Comments

@kenchris
Copy link
Contributor

      static get properties() {
        return {
          foo: String,
          bar: Number,
          whales: { type: Number, reflectToAttribute: true }
        }
      }
whales: 🐳🐳🐳🐳🐳🐳🐳
          
$0.whales
7
$0.getAttribute("whales")
"0"
@abdonrd
Copy link
Contributor

abdonrd commented Jan 21, 2018

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

@kenchris
Copy link
Contributor Author

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.

@ernsheong
Copy link
Contributor

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

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

@sorvell
Copy link
Member

sorvell commented May 1, 2018

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.

@sorvell sorvell closed this as completed May 1, 2018
@sundar-rajavelu
Copy link

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

@blikblum
Copy link

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

@HitkoDev
Copy link

@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)
    }

keanulee pushed a commit that referenced this issue Nov 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants