aboutsummaryrefslogtreecommitdiffstats
path: root/src/animation/Runner.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-12 12:00:03 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-12 13:01:01 +0100
commit6ea72cae2c761848b7db2c9457fd41c62d0336d6 (patch)
tree4d62e3f49a8e4922ed520739e4ab9b42b67e9e97 /src/animation/Runner.js
parentc108c060152add00cac72a4911f6e998ffb4eb83 (diff)
downloadsvg.js-6ea72cae2c761848b7db2c9457fd41c62d0336d6.tar.gz
svg.js-6ea72cae2c761848b7db2c9457fd41c62d0336d6.zip
make List return new lists on method calls, add map to array polyfill so that this works, fix runner
Diffstat (limited to 'src/animation/Runner.js')
-rw-r--r--src/animation/Runner.js32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/animation/Runner.js b/src/animation/Runner.js
index 4de127a..47929fd 100644
--- a/src/animation/Runner.js
+++ b/src/animation/Runner.js
@@ -141,10 +141,11 @@ export default class Runner extends EventTarget {
These methods allow us to attach basic functions to the runner directly
*/
- queue (initFn, runFn, isTransform) {
+ queue (initFn, runFn, retargetFn, isTransform) {
this._queue.push({
initialiser: initFn || noop,
runner: runFn || noop,
+ retarget: retargetFn,
isTransform: isTransform,
initialised: false,
finished: false
@@ -338,8 +339,8 @@ export default class Runner extends EventTarget {
// for the case of transformations, we use the special retarget function
// which has access to the outer scope
- if (this._history[method].caller.isTransform) {
- this._history[method].caller.isTransform(target)
+ if (this._history[method].caller.retarget) {
+ this._history[method].caller.retarget(target)
// for everything else a simple morpher change is sufficient
} else {
this._history[method].morpher.to(target)
@@ -404,6 +405,15 @@ export default class Runner extends EventTarget {
return this
}
+ // TODO: Keep track of all transformations so that deletion is faster
+ clearTransformsFromQueue () {
+ if (!this.done) {
+ this._queue = this._queue.filter((item) => {
+ return !item.isTransform
+ })
+ }
+ }
+
static sanitise (duration, delay, when) {
// Initialise the default parameters
var times = 1
@@ -442,6 +452,8 @@ class FakeRunner {
this.id = id
this.done = done
}
+
+ clearTransformsFromQueue () { }
}
extend([Runner, FakeRunner], {
@@ -538,6 +550,7 @@ class RunnerArray {
let deleteCnt = this.ids.indexOf(id + 1) || 1
this.ids.splice(0, deleteCnt, 0)
this.runners.splice(0, deleteCnt, new FakeRunner())
+ .forEach((r) => r.clearTransformsFromQueue())
return this
}
}
@@ -758,7 +771,7 @@ extend(Runner, {
transforms = { ...newTransforms, origin }
}
- this.queue(setup, run, retarget)
+ this.queue(setup, run, retarget, true)
this._isDeclarative && this._rememberMorpher('transform', morpher)
return this
},
@@ -774,28 +787,31 @@ extend(Runner, {
},
dx (x) {
- return this._queueNumberDelta('dx', x)
+ return this._queueNumberDelta('x', x)
},
dy (y) {
- return this._queueNumberDelta('dy', y)
+ return this._queueNumberDelta('y', y)
},
_queueNumberDelta (method, to) {
to = new SVGNumber(to)
// Try to change the target if we have this method already registerd
- if (this._tryRetargetDelta(method, to)) return this
+ if (this._tryRetarget(method, to)) return this
// Make a morpher and queue the animation
var morpher = new Morphable(this._stepper).to(to)
+ var from = null
this.queue(function () {
- var from = this.element()[method]()
+ from = this.element()[method]()
morpher.from(from)
morpher.to(from + to)
}, function (pos) {
this.element()[method](morpher.at(pos))
return morpher.done()
+ }, function (newTo) {
+ morpher.to(from + new SVGNumber(newTo))
})
// Register the morpher so that if it is changed again, we can retarget it