Skip to content

Instantly share code, notes, and snippets.

@zymsys

zymsys/events.js

Created Apr 21, 2012
Embed
What would you like to do?
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