Skip to content

Instantly share code, notes, and snippets.

@L8D
Created September 24, 2014 07:58
Show Gist options
  • Select an option

  • Save L8D/e271568a4836b0b0d1ce to your computer and use it in GitHub Desktop.

Select an option

Save L8D/e271568a4836b0b0d1ce to your computer and use it in GitHub Desktop.
var Game = React.createClass({
render: function() {
var x = this.props.x,
y = this.props.y;
return (
<svg width={Math.max(x + 10, 200)} height={height: Math.max(y + 10, 200)}>
<circle cx={50} cy={50} r={2} fill="#000" />
<circle cx={x} cy={y} r={2} fill="#000" />
<line x1={50} y1={50} x2={x} y2={y} stroke="#000" />
</svg>
);
}
});
var moves = Rx.Observable.fromEvent(document, 'mousemove'),
downs = Rx.Observable.fromEvent(document, 'mousedown'),
ups = Rx.Observable.fromEvent(document, 'mouseup');
downs.flatMap(function() {
return moves.takeUntil(ups);
}).merge(downs).map(function(event) {
return {x: event.x - 10, y: event.y - 10};
}).subscribe(function(props) {
React.renderComponent(Game(props), document.body);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment