Re: Adding an interface to provide a list of listeners

28.07.2014, 05:09, "Boris Zbarsky" <bzbarsky@MIT.EDU>:
> On 7/27/14, 7:56 PM, Marat Tanalin wrote:
>> šSo if specific listener is not specified, then all listeners of the specified event type are removed at once:
>
> One library adds some listeners, then
> another adds some, then the first removes them all, breaking the second
> library.

If an application removes listeners, then the application probably needs it. Doesn't it?

Note that removal of all listeners at once is already achievable _anyway_ -- just with a somewhat dumb method (replacing original element with its clone). We just need a more elegant/intuitive and more flexible (e.g. with ability to remove listeners of a specific type [e.g. `click`] instead of all listeners of all types) method for this.


> Or worse yet you do this on a <select size="1"> and remove the click
> event listener that opens the dropdown...
>
> Or did you not actually mean _all_ listeners? šPerhaps you meant "all
> the listeners that this script (or this function or some other unit of
> related code yet to be defined) has added"?

By "all listeners" I mean all listeners that are removed by replacing an element with its clone. This, of course, works without breaking any predefined behavioral stuff like SELECT's dropdown action. I.e., I mean listeners that exist from web-developer's perspective, not from implementor's perspective.

Some usecases that I personally did encounter in my practice:

    * a browser's extension that overrides a handler 
      of the browser's built-in element like button. For example, 
      in my UsableHomeButton extension I override the `onclick` 
      property of the Home button. But if original browser listeners 
      have been binded via `addEventListener()` instead of `onclick` 
      property, I would then be forced to use cloning method,
      otherwise I couldn't remove original listeners at all;

    * a user script that modifies how a webpage is functioning -- 
      such script needs a way to remove listeners that the original 
      webpage has.

Of course, to some extent, these specific usecases could be resolved by using a specific-browser's nonstandard method available solely for addons and userscripts, but that would at least mean that the same method wouldn't work in other browser, so some standardizing is desired anyway. Extending existing `removeEventListener()` looks like a natural and elegant way for this.

Received on Monday, 28 July 2014 18:07:39 UTC