Re: [WICG/webcomponents] Proposal: Custom attributes for all elements, enhancements for more complex use cases (Issue #1029)

To me it seems quite straightforward for a component to integrate with a custom attribute by wiring up a getter/setter, and avoids a whole lot of issues that we'd have in proposing an automated way to do this. For example:

```js
customAttributes.define('my-long', class extends Attr {
  get value() {
    return Number(super.value)
  }
  set value(value) {
    super.value = value;
  }
});

customElements.define('my-consumer', class extends HTMLElement {
  get myLong() {
    return this.getAttributeNode('my-long').value
  }
  set myLong(value) {
    this.setAttribute('my-long', value)
  }
});
```

^ That's not _that_ much code and userland libraries can reduce the boilerplate (as they do today), but it saves us having to specify some incredibly messy things which may stall or block such a proposal from existence due to the complexities. Such as the cases @jakearchibald pointed out. There are however more troublesome cases; platform conflicts are one issue but so are userland conflicts... what do you do about attribute definitions clobbering properties on existing custom elements? Either the custom element wins in which case the automagic consistent application of the attribute is no longer consistent, or the attribute wins which breaks the prescribed contract of the custom element.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/1029#issuecomment-2455166850
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/1029/2455166850@github.com>

Received on Monday, 4 November 2024 16:30:59 UTC