Skip to content

Instantly share code, notes, and snippets.

@nramirez
Last active January 9, 2016 18:51
Show Gist options
  • Save nramirez/f87ecc007a73502e7a4a to your computer and use it in GitHub Desktop.
Save nramirez/f87ecc007a73502e7a4a to your computer and use it in GitHub Desktop.
Wedding playlist
var data = [];
var playlist = React.createClass({
getInitialState: function(){
return { lastSong: 0 }
},
componentDidMount: function() {
setInterval(this.loadSongs, 5000);
},
loadSongs: function() {
var lastId = this.state.lastSong;
$.get('/api/loadSongs/' + lastId, function(response){
if (response.data.length > 0) {
data = data.concat(response.data);
this.setState({
lastSong: data[data.length-1]
});
};
});
},
render: function(){
var createRow = function(row){
return (
<tr>
<td>row.name</td>
<td>row.artist</td>
<td>row.gender</td>
</tr>
);
}
var empty = (
<tr>
<td colspan="3"> No hay entradas nuevas</td>
</tr>
);
return (
<table>
<thead>
<tr>
<th>Artist</th>
<th>Song</th>
<th>Gender</th>
</tr>
</thead>
<tbody>
{data.length == 0 ?
empty :
data.map(createRow) }
</tbody>
</table>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment