Re: [w3c/webcomponents] [idea] Expose and API for syncing attributes and properties (#823)

I somewhat agree, but I can also see the benefit of reusing the browser's internal logic to get consistent behaviour between native element attributes and custom element attributes.  Not all engineers I've worked with on custom elements have understood the importance of such consistency and setting attributes or linked properties results in unexpected behaviour.

Providing a very easy to use decorator that gets you the same semantics as native attribute-property links could encourage good practices and even provide use of otherwise unavailable interfaces such as `DOMTokenList`. For example:

```
class MyCarousel extends HTMLElement {
  @attr('autonewslide', { type: 'boolean' }) autoNewSlide;
  @attr('slidedirection', { type: 'tokenlist' }) slideDirection;
  @attr('waittime', { type: 'custom', parser: fn, serializer: fn }) waitTime;
  @attr('onnewslide', { type: 'function' }) onsomething;
}
```

Note: event handler attributes have particularly strange semantics (setting the property does not update the attribute and setting the attribute does not override a previously set property), and there's possibly an argument against enabling those kinds of attributes anyway. 

-- 
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/823#issuecomment-507631352

Received on Tuesday, 2 July 2019 11:15:20 UTC