Skip to content

Instantly share code, notes, and snippets.

@chreekat
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chreekat/24c23a40ddebbad02ab9 to your computer and use it in GitHub Desktop.
Save chreekat/24c23a40ddebbad02ab9 to your computer and use it in GitHub Desktop.
var linkbot = ...;
var LinkbotWheels = React.createClass({
// Update the component's state on every Linkbot event
componentWillMount: function() {
var me = this;
linkbot.register({
wheel: {
3: {
callback: function(wheelEv) {
me.setState({ wheelPositions: wheelEv.positions });
}}
}
});
},
// Set the initial state synchronously
getInitialState: function() {
return {
wheelPositions: linkbot.wheelPositions()
};
},
render: function() {
var tableRows = this.state.wheelPositions.map(function(pos, idx) {
return (
<tr key={idx}>
<td>Wheel {idx}</td>
<td>{pos}</td>
</tr>
);
});
return (
<table>
{tableRows}
</table>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment