- From: Jan Miksovsky <notifications@github.com>
- Date: Tue, 13 Sep 2016 17:27:22 -0700
- To: w3c/webcomponents <webcomponents@noreply.github.com>
- Message-ID: <w3c/webcomponents/issues/565/246869134@github.com>
While many things changed from Custom Elements v0 to v1, in upgrading elements to v1, I've been surprised that that dealing with `observedAttributes` has been, by far, the trickiest issue I've grappled with. It can be tedious and error-prone to keep `observedAttributes` up to date. I've hit numerous bugs that I've eventually traced to the failure to remember to add a new property to `observedAttributes`. It also complicates the creation of component mixins or subclasses, which need to dynamically insert the attribute they're defining into a list of attributes observed by the base class. As @matthewp indicates, the motivation behind `observedAttributes` was performance. Specifically, it was observed that many apps set the `style` attribute programmatically with multiple invocations: ``` this.style.width = newWidth; this.style.height = newHeight; this.style.display = newDisplay; ... ``` Each of those `style` updates would invoke `attributeChangedCallback`. To avoid this problem, `observedAttributes` was introduced. @trusktr's proposal above would help, but I think it'd fall down in the case, e.g., where a mixin/subclass wants to observe an attribute. If a mixin/subclass defined `observedAttributes` with an attribute it was interested in, this would suddenly break base class behavior that had depended on no `observedAttributes` being defined in order to get the default behavior proposed above. Counter-proposal: all attributes _except standard attributes_ always trigger `attributeChangedCallback`. * For custom attributes, it feels like the default behavior should be to invoke `attributeChangedCallback`. * It's rare for a component to want to react to a change in a standard attribute (like `style`), so forcing declaration of that seems acceptable. The use of `observedAttributes` could be reserved for observing standard attributes. * The name of the property could change to `observedStandardAttributes` to reflect the refined semantics. If that member included custom attribute names, those would be ignored. @domenic If I recall, you were the driving force behind the introduction of `observedAttributes`. Given the challenges we're having using this member, do you think it'd be possible to refine how it works? -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/w3c/webcomponents/issues/565#issuecomment-246869134
Received on Wednesday, 14 September 2016 00:27:56 UTC