Indexing HTML Attributes and Unique Indexes

Randy Buchholz work at randybuchholz.com
Wed May 22 17:07:01 UTC 2019


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190522/13dc72b9/attachment.html>


More information about the es-discuss mailing list