Sounds like a job for decorators. `lit-element` provides something very close to at least part of what you seem to want (the getters and setters that is, not the indexing or "distinct" functionality).
Bob ---------- Forwarded message ---------- > From: Randy Buchholz <w...@randybuchholz.com> > To: "es-discuss@mozilla.org" <es-discuss@mozilla.org> > Cc: > Bcc: > Date: Wed, 22 May 2019 17:07:01 +0000 > Subject: Indexing HTML Attributes and Unique Indexes > > I’ve been working with `Custom Elements` and I’m writing a lot of code > against tag attributes. In some cases, I want the attribute values to be > unique on a page (like `id`). It got me wondering about how the engines > handle attribute based searches, and if indexing (with unique/distinct > options) would provide value. I also find myself writing a lot of > boilerplate getters/setters for attributes in the elements. Attribute > handling could be improved by adding some additional support with something > like an `attrib` feature. This would be similar to `get` or `set` in use. > > > > ``` > > class MyElement extends HTMLElement{ > > attrib myAttrib(‘my-attribute’) index distinct; > > } > > ``` > > This would create the attribute `my-attribute` on the tag and element, and > also generate a getter and setter > > ``` > > get myAttrib() { return this.getAttribute(‘my-attribute’); } > > set myAttrib(v) { this.setAttribute(‘my-attribute’, v); } > > ``` > > The `index` flag it would tell the engine it should create a map/hash to > improve search optimization for heavily searched attributes. > > The `distinct` flag would indicate that all values for that attribute > within context (e.g., document) should be unique. This might be used > primarily by IDE’s to generate warnings. > >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss