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

Re: [ambient-light] What illuminance value should be reported for stopped sensor?

From: Tobie Langel via GitHub <sysbot+gh@w3.org>
Date: Mon, 31 Oct 2016 20:24:08 +0000
To: public-device-apis-log@w3.org
Message-ID: <issue_comment.created-257409944-1477945446-sysbot+gh@w3.org>
@alexshalamov, yeah, the UA must generate a new immutable 
`SensorReading` object for each new sensor reading and have 
`Sensor.reading` point to it.

```js
let als = new AmbientLightSensor();
als.start({frequency: 60 });
let als2 = new AmbientLightSensor();
als2.start({ frequency: 25 });

let cachedReading1 = als.reading; // null

// time passes
let cachedReading2 = als.reading; // { illuminance: 23, timestamp: 
87249 }
let cachedReading3 = als.reading; // { illuminance: 23, timestamp: 
87249 }
let als2cachedReading = als2.reading; // { illuminance: 23, timestamp:
 87249 }

// more time passes
let cachedReading4 = als.reading; // { illuminance: 344, timestamp: 
3497979 }

als.stop();
als2.stop();

console.log(cachedReading1.illuminance);
// Uncaught TypeError: Cannot read property 'illuminance' of null(…)
console.log(cachedReading1 === cachedReading2);
// false

console.log(cachedReading2.illuminance);
// 23
console.log(cachedReading3.illuminance);
// 23
console.log(cachedReading2 === cachedReading3);
// true
console.log(als2cachedReading.illuminance);
// 23
console.log(cachedReading2 === als2cachedReading);
// true

console.log(cachedReading4.illuminance);
// 344
console.log(cachedReading3 === cachedReading4);
// false
```


-- 
GitHub Notification of comment by tobie
Please view or discuss this issue at 
https://github.com/w3c/ambient-light/issues/15#issuecomment-257409944 
using your GitHub account
Received on Monday, 31 October 2016 20:24:14 UTC

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