- From: Tobie Langel via GitHub <sysbot+gh@w3.org>
- Date: Sun, 06 Mar 2016 22:07:33 +0000
- To: public-device-apis@w3.org
re @rwaldron's
[comment](https://github.com/w3c/sensors/issues/88#issuecomment-193002528):
Just for kicks changed your first example with a sensor born
deactivated (as in iOS, for example) and that has an
`activate`/`deactivate` couple similar to `resume`/`pause`.
```js
import React from "react";
import Geolocation from "./geolocation-simulator";
import { header } from "./styles.css";
import Title from "react-title-component";
let handlers = new Map();
let geo = new Geolocation({ frequency: 4 });
geo.on("data", coords => {
console.log(`Data Event; received: ${coords.latitude}
${coords.longitude}`);
handlers.forEach(handler => handler(coords));
});
export default React.createClass({
getInitialState() {
return {
latitude: null,
longitude: null,
};
},
componentDidMount() {
geo.activate();
handlers.set(this, coords => {
this.setState({ ...coords });
});
},
componentWillUnmount() {
geo.deactivate();
handlers.clear();
},
render() {
return (
<div>
<Title render="Map"/>
<h2 className={header}>Longitude & Latitude</h2>
<ul>
<li>Latitude: {this.state.latitude}</li>
<li>Longitude: {this.state.longitude}</li>
</ul>
</div>
)
}
});
```
--
GitHub Notification of comment by tobie
Please view or discuss this issue at
https://github.com/w3c/sensors/issues/88#issuecomment-193005394 using
your GitHub account
Received on Sunday, 6 March 2016 22:07:34 UTC