Last active
August 29, 2015 14:13
-
-
Save chreekat/24c23a40ddebbad02ab9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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