Skip to content

[RRFC] Add additional decorators to help observe property changes and create event properties #28

Open
@sorvell

Description

@sorvell
  • [ X] I searched for an existing RRFC which might be relevant to my RRFC

Motivation

Lit has proven that declarative setup via decorators is exceptionally convenient and useful. Additional decorators could be explored in a lit-labs package for potential inclusion based on feedback. Two obvious candidates are @observe and @event.

The @observe decorator would be used on a class member function which would be called when the noted propery changes.

The @event decorator would be used on a property intended to behave like a platform event property, e.g. onclick.

Example

A simple @observe decorator is prototyped here.

A simple @event decorator is prototyped here.

class MyElement extends LitElement {

  @property()
  foo = 'foo';

  @observe('foo')
  #fooChanged(value, old, name) {...}

  @event('hiya')
  onHiya?: EventListener;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions