var Game = React.createClass({ mixins: [SetIntervalMixin], // TODO: Declare all propTypes propTypes: { title: React.PropTypes.string, players: React.PropTypes.array, id: React.PropTypes.number, url: React.PropTypes.string, play_to_beat_string: React.PropTypes.string }, getInitialState: function() { return { data: null, players: [], title: "", play_to_beat_string: "", is_started: false, is_joinable: false, is_startable: false }; }, loadGameFromServer: function() { $.getJSON(this.props.url, function(result) { if (this.isMounted()) { this.setState({ data: result }); } }.bind(this)); }, componentDidMount: function() { this.loadGameFromServer(); this.setInterval(this.loadGameFromServer, 3000); }, handlePlayHandSubmit: function(card_ids) { $.ajax({ url: this.props.url + '/play_hand', type: 'PATCH', dataType: 'json', data: card_ids, success: function(data) { // TODO: Set state instead of this custom method? this.loadGameFromServer(); }.bind(this), error: function(xhr, status, err) { console.error(this.props.url, status, err.toString()); }.bind(this) }); }, handleStart: function() { $.ajax({ url: this.props.url + '/start', type: 'POST', dataType: 'json', complete: function (jqXHR, textStatus) { // callback }, success: function (data, textStatus, jqXHR) { // success callback }, error: function (jqXHR, textStatus, errorThrown) { // error callback } }); }, handleJoin: function() { $.ajax({ url: this.props.url + '/join', type: 'POST', dataType: 'json', complete: function (jqXHR, textStatus) { // callback }, success: function (data, textStatus, jqXHR) { // success callback }, error: function (jqXHR, textStatus, errorThrown) { // error callback } }); }, render: function() { if (!this.state.data) { return