Re: [battery] Should getBattery() always return the same promise?

On Tue, Jul 1, 2014 at 6:03 AM, Mounir Lamouri <> 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: . 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

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.


Received on Tuesday, 1 July 2014 21:16:18 UTC