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

Add some decorators #1784

Merged
merged 4 commits into from
Oct 16, 2018
Merged

Add some decorators #1784

merged 4 commits into from
Oct 16, 2018

Conversation

balloob
Copy link
Member

@balloob balloob commented Oct 16, 2018

Somehow we are not enforcing prettier, allowing the button PR to slip through unprettified. Those changes are included in this PR.

Decorators is a stage 2 draft proposal. It allows decorating classes, properties and methods and enhance them. It has been included in TypeScript under an experimental flag.

Lit Element ships with a bunch of decorators that make writing elements even easier:

  • @customElement("hui-entity-button-card") to register a class as a custom element.
  • @property(options) to register a field as a property. That way we don't have to define a properties method. (btw, we should only mark fields as properties if we want changing them to trigger a render)
  • @query('.header') or @queryAll('.card') to turn a property into a getter that returns the results of querySelector or querySelectorAll on the shadow root
    @query('.header')
    protected headerElement!: HTMLDivElement;
  • Bonus decorator: material web components have an observer decorator: @observer((value, old) => { … }) . The observer method will be called whenever the value has changed and the DOM has been rendered (during the updated lifecycle).

@ghost ghost assigned balloob Oct 16, 2018
@ghost ghost added the in progress label Oct 16, 2018
@balloob balloob merged commit a7684d7 into master Oct 16, 2018
@balloob balloob deleted the lit-decorators branch October 16, 2018 21:30
@ghost ghost removed the in progress label Oct 16, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants