Skip to content

Instantly share code, notes, and snippets.

@BMeyerKC
Last active December 14, 2015 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BMeyerKC/5120862 to your computer and use it in GitHub Desktop.
Save BMeyerKC/5120862 to your computer and use it in GitHub Desktop.
Recursive function call that speeds up. Using Meteor template events.
Meteor.startup(function () {
$(function(){
$(document).on("mouseup", function (){
clearTimeout(pointsTimer);
});
});
// code to run on client at startup
});
var pointsTimer, pointsPlayer, timerStart, addTimer;
var playerScoreAdd = function () {
addTimer++;
Players.update({_id: pointsPlayer._id}, {$set: {"score": pointsPlayer.score + 1}});
pointsTimer = setTimeout(playerScoreAdd, timerStart / addTimer);
};
var playerScoreSubtract = function () {
addTimer++;
Players.update({_id: pointsPlayer._id}, {$set: {"score": pointsPlayer.score - 1}});
pointsTimer = setTimeout(playerScoreSubtract, timerStart / addTimer);
};
Template.players.player = function () {
return Players.find();
};
Template.players.events = {
"mousedown .playerScoreSubtract": function (event, template) {
addTimer = 1;
pointsPlayer = this;
timerStart = 1000;
playerScoreSubtract();
},
"mousedown .playerScoreAdd": function (event, template) {
addTimer = 1;
pointsPlayer = this;
timerStart = 1000;
playerScoreAdd();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment