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鈥檒l 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

Comments

Projects
None yet
7 participants
@kenchris
Contributor

kenchris commented Jan 21, 2018

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

This comment has been minimized.

Show comment
Hide comment
@abdonrd

abdonrd Jan 21, 2018

Contributor

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

Contributor

abdonrd commented Jan 21, 2018

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

@kenchris

This comment has been minimized.

Show comment
Hide comment
@kenchris

kenchris Jan 21, 2018

Contributor

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.

Contributor

kenchris commented Jan 21, 2018

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

This comment has been minimized.

Show comment
Hide comment
@ernsheong

ernsheong Feb 18, 2018

Contributor

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

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

ernsheong commented Feb 18, 2018

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

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

This comment has been minimized.

Show comment
Hide comment
@sorvell

sorvell May 1, 2018

Member

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.

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 May 1, 2018

@sundar-rajavelu

This comment has been minimized.

Show comment
Hide comment
@sundar-rajavelu

sundar-rajavelu May 29, 2018

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

sundar-rajavelu commented May 29, 2018

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

@blikblum

This comment has been minimized.

Show comment
Hide comment
@blikblum

blikblum May 29, 2018

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 commented May 29, 2018

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

This comment has been minimized.

Show comment
Hide comment
@HitkoDev

HitkoDev Jun 14, 2018

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

HitkoDev commented Jun 14, 2018

@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)
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment