Indexing HTML Attributes and Unique Indexes (Randy Buchholz)

Bob Myers rtm at gol.com
Wed May 22 19:14:24 UTC 2019


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 <work at randybuchholz.com>
> To: "es-discuss at mozilla.org" <es-discuss at 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.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190522/960f48af/attachment-0001.html>


More information about the es-discuss mailing list