aboutsummaryrefslogtreecommitdiffstats
path: root/src/animation/Animator.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/animation/Animator.js')
-rw-r--r--src/animation/Animator.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/animation/Animator.js b/src/animation/Animator.js
index 64570eb..390b200 100644
--- a/src/animation/Animator.js
+++ b/src/animation/Animator.js
@@ -5,6 +5,7 @@ const Animator = {
nextDraw: null,
frames: new Queue(),
timeouts: new Queue(),
+ immediates: new Queue(),
timer: () => globals.window.performance || globals.window.Date,
transforms: [],
@@ -38,6 +39,17 @@ const Animator = {
return node
},
+ immediate (fn) {
+ // Add the immediate fn to the end of the queue
+ var node = Animator.immediates.push(fn)
+ // Request another animation frame if we need one
+ if (Animator.nextDraw === null) {
+ Animator.nextDraw = globals.window.requestAnimationFrame(Animator._draw)
+ }
+
+ return node
+ },
+
cancelFrame (node) {
node != null && Animator.frames.remove(node)
},
@@ -46,6 +58,10 @@ const Animator = {
node != null && Animator.timeouts.remove(node)
},
+ cancelImmediate (node) {
+ node != null && Animator.immediates.remove(node)
+ },
+
_draw (now) {
// Run all the timeouts we can run, if they are not ready yet, add them
// to the end of the queue immediately! (bad timeouts!!! [sarcasm])
@@ -70,6 +86,11 @@ const Animator = {
nextFrame.run()
}
+ var nextImmediate = null
+ while ((nextImmediate = Animator.immediates.shift())) {
+ nextImmediate()
+ }
+
// If we have remaining timeouts or frames, draw until we don't anymore
Animator.nextDraw = Animator.timeouts.first() || Animator.frames.first()
? globals.window.requestAnimationFrame(Animator._draw)