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

On Fri, Nov 6, 2015 at 12:44 PM, Olli Pettay <olli@pettay.fi> wrote:
> On 11/06/2015 09:28 PM, Justin Fagnani wrote:
>>
>> You can also override addEventListener/removeEventListener on your
>> element. My concern with that, and possibly an event listener change
>> callback, is
>> that it only works reliably for non-bubbling events.
>
> How even with those? One could just add capturing event listener higher up
> in the tree.
> You need to override addEventListener on EventTarget, and also relevant
> onfoo EventHandler setters on Window and Document and *Element prototypes,
> but unfortunately even that doesn't catch onfoo content attributes (<div
> onclick="doSomething">). But one could use MutationObserver then to
> observe changes to DOM.

This problem also applies to the original proposal in this thread.

Even if we add the ability to detect when an eventlistener is added to
a custom element, what happens if an eventlistener is added to an
ancestor node? Or if the custom element is moved into a new element
which already has an ancestor with such an event listener.

/ Jonas

Received on Friday, 6 November 2015 22:03:26 UTC