W3C home > Mailing lists > Public > public-device-apis@w3.org > September 2011

Re: addEventListener and side-effects

From: James Graham <jgraham@opera.com>
Date: Tue, 6 Sep 2011 18:03:56 +0200 (CEST)
To: Robin Berjon <robin@berjon.com>
cc: James Graham <jgraham@opera.com>, www-dom@w3.org, public-device-apis@w3.org
Message-ID: <alpine.DEB.2.00.1109061756201.26208@sirius>


On Tue, 6 Sep 2011, Robin Berjon wrote:

> On Sep 6, 2011, at 14:59 , James Graham wrote:
>> On Tue, 6 Sep 2011, Robin Berjon wrote:
>>> as most of you are probably aware, there have been recent threads on both the Geo list[0] and the DAP list[1][2] about calls to addEventListener producing side-effects (or purported side-effects).
>>
>> I am very much against addEventListener having side effects. Where we 
>> have nice simple invariants in the platform it is good to keep them.
>
> Right, but part of the question is whether triggering an event upon 
> registration is indeed a side-effect. Presumably, there is necessarily 
> an effect of event registration (certainly for this type of event), 
> which causes some code to be initialised with a specific intent 
> (dispatching events to a given window about orientation sensors or the 
> level of a battery).

Not at all. Consider the case where one registers multiple event handlers 
for a single event type. Even if the first has some implementation-detail 
side effect like turning on the GPS, later event registations don't. 
Having extra events every time some unrelated piece of code from a 
different library adds an event listener seems wholly undesirable. It is 
much better to keep the simple model where events are fired regardless of 
whether there is a handler listening for them, and let anything else be a 
UA optimisation.
Received on Tuesday, 6 September 2011 16:04:43 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 9 May 2012 00:14:22 GMT