Re: [w3c/webcomponents] [idea] Make use of `observedAttributes` optional (#565)

> I think having observedAttributes either an Array or a RegExp would solve pretty much every issue raised in here. "catch-all" would be as easy as /.*/ and it's possible to filter out stuff like /^(?!data-)/ or /^(?!style$)/ to rule out style only.

With caching, I think this could be useful, and adding it to spec later would remain backwards-compatible. It would also be opt-in, so if an array is provided then no extra memory footprint for the cache list. 

Although I like the idea of using RegExp for observedAttributes, extending a super class's observedAttributes then becomes tricky (imagine super observedAttributes is a list, and the child class wants to have a RegExp).

> Would it be any more expensive (memory-wise) than an author providing a list of 10 strings rather than a list of two expressions? 

The phrase "list of two expressions" makes me think: maybe observedAttributes can be a list as now, but can also contain RegExps as well (with caching as mentioned). In this case, extending super isn't so bad.

> Defining the list of standard attributes is hard because the list is not finalized. As more attributes are added to the standard, components which relied that those attributes to be not standard will fail to observe the attribute value changes even if the attributes only had a meaning in some builtin elements. As such, this approach poses a serious forward compatibility concern.

>From a design-pattern perspective, would it be more web-manifesto-friendly for "global" attributes to be observedAttributes on a base class that all elements extend from, like HTMLElement? That would be a breaking change after v1, but I feel like it makes sense in order for things to be explainable rather than just magic. The downside is that calling super would be required for all custom elements or the custom element would no longer observe things like `style`:

```js
class MyElement extends HTMLElement {
  static get observedAttributes() {
    return super.observedAttributes().concat(...)
  }
}
```

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

Received on Wednesday, 21 September 2016 00:02:43 UTC