- From: Justin Fagnani <notifications@github.com>
- Date: Fri, 26 Feb 2021 13:44:44 -0800
- To: WICG/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Friday, 26 February 2021 21:44:56 UTC
I'd rather keep the shape-defining aspects of a class declaration in the class body so that parsers, type-checkers, and the VMs can understand the class shape. If decorators advance, I think some kind of built-in decorators would offer a nicer way of associating an attribute and property. I know people have posited a `@reflect` attribute before. I think an `@attribute` decorator would be easy to understand: ```ts const attribute = Element.attributeDecorator; class MyElement extends HTMLElement { @attribute({name: 'serial-number', type: Number}) accessor serialNumber; } ``` The question raised here would be how to populate `observedAttributes` from decorators. Decorators will be able to add metadata to a class, so a utility function could gather the attribute names. Maybe it's even possible that HTMLElement could have a default implementation of `static observedAttributes` that return this. I don't know how viable that it. ```ts class MyElement extends HTMLElement { // 'foo' is an additional observed attribute not declared with a decorated field. static observedAttributes = ['foo', ...Element.getDeclaredAttributeNames(this)]; } ``` -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/WICG/webcomponents/issues/913#issuecomment-786910070
Received on Friday, 26 February 2021 21:44:56 UTC