Re: [WICG/webcomponents] Using attributes as properties (#913)

To clarify Justin's thought, decorators will be the only way to legitimately make this work in such a way that two things happen at once:

1. the class shape is defined using class fields, therefore before the `customElements.define` call the shape of the class is full known using `class `semantics
2. attributes can be mapped to JS properties, and vice versa.

Otherwise, with an approach like `static observedAttributes = { foo: Element.attributes.number(123) }`, you may want the JS property to reflect back to the attribute, and in order for that to be possible the `customElements.define` call would need to modify the class (f.e. add a getter/setter pair on the prototype, plus extend the class so as to override class fields which use [[Define]] semantics) so that when a JS property is modified it would be able to react and serialize the value back into the attribute.

With decorators, we get both at once: we define JS properties, and the decorators establish the desired to attributes and from attributes behavior.

-- 
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-803839102

Received on Monday, 22 March 2021 07:40:24 UTC