Skip to content

Commit

Permalink
Upgrade to newer version of Timer.js with fixed API for Timer#bind.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmycuadra committed Nov 23, 2012
1 parent af5acb4 commit 1e6dfb1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion source/javascripts/models/store.js.coffee
Expand Up @@ -19,7 +19,7 @@ class ph.Store extends Backbone.Model
@on("change", @persist, this)

@timer = new Timer
@timer.every(1, @addTick)
@timer.every(100, @addTick)
@timer.start()

checkHighScore: (store, newScore) ->
Expand Down
11 changes: 3 additions & 8 deletions source/javascripts/vendor/timer.js
Expand Up @@ -69,7 +69,7 @@
setTimeout(function loopsyloop() {
self._ticks++;
for (var i = 0, l = self._notifications.length; i < l; i++) {
if (self._ticks % self._notifications[i].ticks === 0) {
if (self._notifications[i] && self._ticks % self._notifications[i].ticks === 0) {
self._notifications[i].callback.call(self._notifications[i], {
ticks: self._ticks,
resolution: self._resolution
Expand Down Expand Up @@ -111,12 +111,7 @@
},
bind: function(when, callback) {
if (when && callback) {
var ticks;
if (typeof when === 'number') {
ticks = when;
} else {
ticks = millisecondsToTicks(timeStringToMilliseconds(when), this._resolution);
}
var ticks = millisecondsToTicks(timeStringToMilliseconds(when), this._resolution);
this._notifications.push({
ticks: ticks,
callback: callback
Expand All @@ -129,7 +124,7 @@
this._notifications = [];
} else {
for (var i = 0, l = this._notifications.length; i < l; i++) {
if (this._notifications[i].callback === callback) {
if (this._notifications[i] && this._notifications[i].callback === callback) {
this._notifications.splice(i, 1);
}
}
Expand Down

0 comments on commit 1e6dfb1

Please sign in to comment.