- From: Rick Waldron <waldron.rick@gmail.com>
- Date: Tue, 1 Jul 2014 17:15:29 -0400
- To: Mounir Lamouri <mounir@lamouri.fr>
- Cc: public-device-apis <public-device-apis@w3.org>, Domenic Denicola <domenic@domenicdenicola.com>
- Message-ID: <CAHfnhfrgg5Gy6bdDx-EZskUFrA5r4fvh8=8TcRyRq3UHb5K+sw@mail.gmail.com>
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:16:18 UTC