summaryrefslogtreecommitdiffstats
path: root/src/animation/Animator.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-12-07 15:35:41 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-12-07 15:35:41 +0100
commit7b02d60829d1151a9fd1e726a0a995b92b165328 (patch)
tree5a7c86988fedd7420d45336ee36edf98e109e8a1 /src/animation/Animator.js
parent5161dfdb3a08490da0ae1c5c8b6515eb0ae0da30 (diff)
downloadsvg.js-7b02d60829d1151a9fd1e726a0a995b92b165328.tar.gz
svg.js-7b02d60829d1151a9fd1e726a0a995b92b165328.zip
Release 3.0.43.0.4
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)