Skip to content

Instantly share code, notes, and snippets.

@zymsys
Created April 21, 2012 05:53
Show Gist options
  • Save zymsys/2434519 to your computer and use it in GitHub Desktop.
Save zymsys/2434519 to your computer and use it in GitHub Desktop.
Meteor First Impressions
Template.leaderboard.events = {
'click input.inc': function () {
Players.update(Session.get("selected_player"), {$inc: {score: 5}});
},
'click #sort': function () {
Session.set("sort_by_name", !Session.get("sort_by_name"));
}
};
Template.leaderboard.players = function () {
var sort = Session.get("sort_by_name") ?
{name: 1, score: -1} :
{score: -1, name: 1};
return Players.find({}, {sort: sort});
};
<button id="sort">Sort by {{#if sort_by_name}}Score{{else}}Name{{/if}}</button>
Template.leaderboard.sort_by_name = function () {
return Session.get("sort_by_name");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment