W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2015

Re: Callback when an event handler has been added to a custom element

From: Elliott Sprehn <esprehn@chromium.org>
Date: Fri, 6 Nov 2015 21:35:56 -0800
Message-ID: <CAO9Q3iLnhSgZ8pEyqFXeT6HA6OLozE30m-J+bFg4UgWwPrc52A@mail.gmail.com>
To: Domenic Denicola <d@domenic.me>
Cc: Mitar <mmitar@gmail.com>, public-webapps <public-webapps@w3.org>
On Fri, Nov 6, 2015 at 5:12 PM, Domenic Denicola <d@domenic.me> wrote:

> In general I would be cautious about this kind of API. Events are not
> expected to have side effects, and adding listeners should not cause an
> (observable) action. See e.g.
> https://dom.spec.whatwg.org/#action-versus-occurance which tries to
> explain this in some detail. A better design in your case would probably be
> to have a specific method on the custom element which "starts" it (and thus
> starts its associated message port).
>
> As such I don't think we should add such a capability to the custom
> element API (or elsewhere in the platform). Although it is possible to use
> such callbacks for "good" (using them only to perform unobservable
> optimizations, like lazy initialization), it is way too easy to use them
> for "evil" (causing observable effects that would better be allocated to
> dedicated action-causing methods).
>
>
I agree, this doesn't seem like something authors should do. You element
should use the attachedCallback to "start" doing something, and the
detachedCallback to stop. You can also have an explicit start() API so
callers could make it begin before it's been inserted into the page. Events
are passive notification of the operation of the element.

- E
Received on Saturday, 7 November 2015 05:37:06 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:14:58 UTC