W3C home > Mailing lists > Public > public-script-coord@w3.org > July to September 2014

RE: Ambient light API redesign

From: Domenic Denicola <domenic@domenicdenicola.com>
Date: Mon, 8 Sep 2014 09:56:59 +0000
To: Mounir Lamouri <mounir@lamouri.fr>, Rick Waldron <waldron.rick@gmail.com>, Tim Volodine <timvolodine@google.com>
CC: Tobie Langel <tobie.langel@gmail.com>, Marcos Caceres <marcos@marcosc.com>, Jonas Sicking <jonas@sicking.cc>, "public-device-apis@w3.org" <public-device-apis@w3.org>, Anssi Kostiainen <anssi.kostiainen@intel.com>, public-script-coord <public-script-coord@w3.org>, Doug Turner <dougt@mozilla.com>, "Anne van Kesteren" <annevk@annevk.nl>
Message-ID: <239721e7ffe84ea7a80c8bb1bc840a60@BN1PR05MB325.namprd05.prod.outlook.com>
I like Rick's proposal especially from a theoretical level since it has constructors, whereas the async-acquisition proposal does not. But I see your point about the initial `undefined` value. If you'll indulge a bit of musing...

It's not that I think constructors are an inherent good, or even that developers love them. But, they are important for rationalizing the platform's JS interface. With that in mind, how do we rationalize the async-acquisition version?

It's interesting, because unlike many constructor-less APIs, there is no browser-only magic in the async-acquisition API. It simply ensures that the sensor is constructed with an initial value. That is, you could envision it being implemented as:

```js
navigator.getDeviceOrientationSensor = options => {
  var sensor = new DeviceOrientationSensor(options);
  return DeviceOrientationSensor.requestValue().then(v => {
    sensor.value = v;
    return sensor;
  });
};
```

Alternately, if you don't like `sensor.value` being writable (why not?) you could envision it as

```js
navigator.deviceOrientation.getSensor = options => {
  return navigator.deviceOrientation.getCurrentValue().then(v => {
    return new DeviceOrientationSensor(Object.assign({ value: v }, options));
  });
};
```

What's interesting is that, keeping in mind the why-constructors mindset I point out above, you don't even have to expose the constructor on the global scope, if you think it is a bad developer-facing interface. All I ask is that it exist, such that we have a rational explanation for instances of DeviceOrientationSensor being created.
Received on Monday, 8 September 2014 09:57:31 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:22 UTC