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

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