Skip to content

Commit

Permalink
initialize timeobject
Browse files Browse the repository at this point in the history
  • Loading branch information
meodai committed Mar 20, 2015
1 parent 797a8b0 commit 6839b84
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ticktack.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
root.ticktack = factory();
}
}(this, function () {
var callbacks, registeredCallbacks, tick, getTimeObject, runCallbacks, timeObject, runCallback, initLoop;
var callbacks, registeredCallbacks, tick, getTimeObject, runCallbacks, timeObject, runCallback, initLoop, setTimeObject;

// Initializing callback objects
callbacks = {};
Expand Down Expand Up @@ -127,15 +127,20 @@
return digits;
};


setTimeObject = function() {
// get new data structure
timeObject = getTimeObject(timeObject);
};

/**
* tick : loop used for RAF also applies the callbacks
* @returns {void}
*/
tick = function () {
window.requestAnimationFrame(tick);

// get new data structure
timeObject = getTimeObject(timeObject);
setTimeObject();
// runs callbacks
runCallbacks();
};
Expand All @@ -145,6 +150,7 @@
* @returns {void}
*/
initLoop = function () {
setTimeObject();
window.requestAnimationFrame(tick);
// makes sure initLoop is called only once
initLoop = function () {};
Expand All @@ -166,7 +172,7 @@

callbacks[eventName].push(callback);

window.requestAnimationFrame(function() {
window.requestAnimationFrame(function () {
// Makes sure an hour event is called instantly, in just in 54 minutes
runCallback(callback, eventName);
});
Expand Down

0 comments on commit 6839b84

Please sign in to comment.