[sensors] Sensor construction improvements

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