- From: Mounir Lamouri <mounir@lamouri.fr>
- Date: Wed, 02 Jul 2014 07:20:14 +1000
- To: public-device-apis@w3.org
See http://lists.w3.org/Archives/Public/public-device-apis/2014Apr/0037.html There was a CfC about that too. -- Mounir On Wed, 2 Jul 2014, at 07:15, Rick Waldron wrote: > On Tue, Jul 1, 2014 at 6:03 AM, Mounir Lamouri <mounir@lamouri.fr> wrote: > > > Hi, > > > > When I wrote the getBattery() prose, I made it so that getBattery() > > would return a new promise every time it is called but it would always > > return the same BatteryManager when the promise is resolved. > > > > I realised that this requirement probably doesn't make much sense and we > > might want to spec getBattery() as returning always the same promise. In > > other words, navigator.getBattery() === navigator.getBattery(). The > > intent isn't really to get the equality but that way, we simplify the > > implementation because implementing this only require to keep track of > > that one promise. > > > > > Is there a design history document or thread that explains the reasoning > that lead to an API that returns a promise here? The battery exists > before > the browser ever loads a site and its JavaScript files, so why does > `getBattery` need to be a promise? The "latest published" Battery Status > API spec makes more sense: navigator.battery is always a single instance > of > BatteryManager that exists as specified here: > http://www.w3.org/TR/battery-status/#navigatorbattery-interface . Why > does > it need to be "requested" via a "getBattery" API that itself doesn't > return > a BatteryManager object, but promises to produce one (and always the same > one)? > > If it's always the same BatteryManager instance, it's not clear how this > API usage: > > navigator.getBattery().then(function(battery) { > battery.onlevelchange = function() { > console.log("level changed!"); > }; > }); > > > ... is at all superior to this: > > navigator.battery.onlevelchange = function() { > console.log("level changed!"); > }); > > > Even if the argument is that not all code needs or wants to allocate the > BatteryManager, then the solution is simply to make `navigator.battery` > an > accessor to the BatteryManager instance. > > > Rick
Received on Tuesday, 1 July 2014 21:20:39 UTC