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: Domenic Denicola <d@domenic.me>
Date: Sat, 7 Nov 2015 01:12:42 +0000
To: Mitar <mmitar@gmail.com>, public-webapps <public-webapps@w3.org>
Message-ID: <CY1PR0501MB1369D084B69D20ABF796656BDF170@CY1PR0501MB1369.namprd05.prod.outlook.com>
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).

Received on Saturday, 7 November 2015 01:13:15 UTC

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