Skip to content

Instantly share code, notes, and snippets.

@Breta01
Last active October 26, 2016 18:49
Show Gist options
  • Save Breta01/2952086da1b4afe4b5a8b6ea32f26cb0 to your computer and use it in GitHub Desktop.
Save Breta01/2952086da1b4afe4b5a8b6ea32f26cb0 to your computer and use it in GitHub Desktop.
import React from 'react';
import Table from './Table';
const Dashboard = React.createClass({
// Function where the magic happens :D
sort_by: function(field, reverse, primer) {
var key = primer ? function(x) {return primer(x[field])} :
function(x) {return x[field]};
reverse = !reverse ? 1 : -1;
return function (a, b) {
return a = key(a), b = key(b), reverse * ((a > b) - (b > a));
};
},
render: function() {
const { stats } = this.props;
// Sorting by timestamp and reversing order
stats.sort(this.sort_by('timestamp', true));
return (
<div className="dashboard">
<h1>Dashboard</h1>
<Table stats={stats.slice(0, 10)} />
</div>
);
}
});
export default Dashboard;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment