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: Justin Fagnani <justinfagnani@google.com>
Date: Fri, 6 Nov 2015 13:20:49 -0800
Message-ID: <CAEKsHmB4LY7YhoUYh7aoCZvfrtsAr+VzcjxENjh4QM5N_QNDfQ@mail.gmail.com>
To: Olli Pettay <olli@pettay.fi>
Cc: Travis Leithead <travis.leithead@microsoft.com>, Mitar <mmitar@gmail.com>, public-webapps <public-webapps@w3.org>
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.
>

Good point. I forgot that capturing works with non-bubbling events :(


> 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.
>
>
> -Olli
>
>
>
>> On Thu, Nov 5, 2015 at 4:16 PM, Travis Leithead <
>> travis.leithead@microsoft.com <mailto:travis.leithead@microsoft.com>>
>> wrote:
>>
>>     Interesting. Alternatively, you can add .onwhatever handlers, as well
>> as define your own overload of addEventListener (which will be called
>>     instead of the EventTarget.addEventListener method). That way you can
>> capture all attempts at setting events on your element.
>>
>>     -----Original Message-----
>>     From: Mitar [mailto:mmitar@gmail.com <mailto:mmitar@gmail.com>]
>>     Sent: Thursday, November 5, 2015 4:05 PM
>>     To: public-webapps <public-webapps@w3.org <mailto:
>> public-webapps@w3.org>>
>>     Subject: Callback when an event handler has been added to a custom
>> element
>>
>>     Hi!
>>
>>     We are using message ports to communicate with our logic and are
>> wrapping the API into a custom element. The issue is that we would like to
>> call
>>     start on a message port only after user has registered an event
>> handler on the custom element instance. But it seems there is no way to get
>> a
>>     callback when an event handler is added.
>>
>>     So I am suggesting that there should be a callback every time an
>> event listener is added to a custom element (and possibly one when removed).
>>
>>
>>     Mitar
>>
>>     --
>>     http://mitar.tnode.com/
>>     https://twitter.com/mitar_m
>>
>>
>>
>
Received on Friday, 6 November 2015 21:21:39 UTC

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