W3C home > Mailing lists > Public > public-device-apis-log@w3.org > October 2016

[sensors] Sensor construction improvements

From: Mikhail Pozdnyakov via GitHub <sysbot+gh@w3.org>
Date: Mon, 03 Oct 2016 09:52:27 +0000
To: public-device-apis-log@w3.org
Message-ID: <issues.opened-180601440-1475488346-sysbot+gh@w3.org>
pozdnyakov has just created a new issue for 
https://github.com/w3c/sensors:

== Sensor construction improvements ==
On most of the web engines, platform sensor construction requires an 
async call to obtain information about available sensors and their 
capabilities.
Also in general, constructors should only create and initialize new 
instance of a class and set its data structures while avoid executing 
any tasks, therefore constructor should be a pure function without any
 side effects.
However at the moment [sensor construction 
procedure](https://w3c.github.io/sensors/#construct-sensor-object)  
contains steps which require platform data, e.g. default sensor 
configuration (pls see https://github.com/w3c/sensors/issues/128) or 
reporting mode.
Possible solutions are:
1) Explicitly mention in the specification that constructor has no 
data about real sensors on the platform (it will be fetched only on 
`start()` call, so some steps should be moved there). Ideally, we 
should use constructor only for initialization and not execute any 
tasks there.

or

2) Make construction asynchronous  for example using the following API
 proposal:

- Introduce  async sensor construction using promises.

- Each concrete sensor specification introduces a dedicated static 
‘request’ method to the Generic 
‘Sensor’ API, e.g. :
     ```
partial interface Sensor {
               Promise<AmbientLightSensor> requestAmbientLight();
}; 
```


- The introduced ‘request’ function might optionally accept sensor 
construction parameters. The ‘request’ function parameters should be 
specified separately for each sensor type.
```
partial interface Sensor {
      Promise<Accelerometer> requestAccelerometer(optional bool 
includeGravity);
 };
```



Please view or discuss this issue at 
https://github.com/w3c/sensors/issues/138 using your GitHub account
Received on Monday, 3 October 2016 09:52:38 UTC

This archive was generated by hypermail 2.3.1 : Monday, 23 October 2017 12:18:52 UTC