- From: Marcos Caceres <w3c@marcosc.com>
- Date: Fri, 25 May 2012 17:50:22 +0100
- To: Anssi Kostiainen <anssi.kostiainen@nokia.com>
- Cc: "public-device-apis@w3.org" <public-device-apis@w3.org>
On Friday, May 25, 2012 at 5:31 PM, Anssi Kostiainen wrote: > Hi Marcos, > > On 25.5.2012, at 14.36, ext Marcos Caceres wrote: > > This looks even better, great work! > > One thing I noticed is that the polyfill is firing events even if there are no listeners registered (I remember you commented about this earlier so I checked how your polyfill behaves). This is really a QoI issue, and the spec is intentionally silent on this. > If you wish, you could augment addEventListener and start firing only when there are listeners registered, something like (using device proximity as an example): > > var p = Window.prototype; > p._addEventListener = p.addEventListener; > p.addEventListener = function (type, callback, capture) { > if (type === 'deviceproximity') { > // start firing events, if not already > } > this._addEventListener(type, callback, capture); > }; > > ... and stop firing when all the listeners are removed (and handle .ondeviceproximity similarly). That said, augmenting built-in objects can be risky, so this may not be worth it. > > Btw. All this relates to the popular topic of addEventListener side effects ... > Yeah… I didn't want to do that because of the world famous side effects - so I just let it run (not great for battery, cpu, I imagine). I can control the window.onwhatever because I can start "sensor.sense()" and the yet to be implemented "sensor.stop()" for those through the [[Get]] method (but that's again a side effect, d'oh!); but like you coded above, the window.addEventListener() will have side effects if they turn the sensor on (I don't think we should pretend that it won't) :( Not sure how to proceed without having some explicit means of turning on the sensor through JS: window.navigator.deviceproximity.enable() … or something that no one will like :) > > Anyway, thanks for the cool polyfill and the test suite! > Thank you for taking a looksy, and thanks for updating spec :)
Received on Friday, 25 May 2012 16:51:43 UTC