mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
added tween.destroy() method + unit tests
This commit is contained in:
13
src/Tween.js
13
src/Tween.js
@@ -78,7 +78,9 @@
|
|||||||
this.reset();
|
this.reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// start/diff object = attrs.nodeId.tweenId.attr
|
||||||
Kinetic.Tween.attrs = {};
|
Kinetic.Tween.attrs = {};
|
||||||
|
// tweenId = tweens.nodeId.attr
|
||||||
Kinetic.Tween.tweens = {};
|
Kinetic.Tween.tweens = {};
|
||||||
|
|
||||||
Kinetic.Tween.prototype = {
|
Kinetic.Tween.prototype = {
|
||||||
@@ -238,7 +240,18 @@
|
|||||||
* @memberof Kinetic.Tween.prototype
|
* @memberof Kinetic.Tween.prototype
|
||||||
*/
|
*/
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
|
var nodeId = this.node._id,
|
||||||
|
thisId = this._id,
|
||||||
|
attrs = Kinetic.Tween.tweens[nodeId],
|
||||||
|
key;
|
||||||
|
|
||||||
|
this.pause();
|
||||||
|
|
||||||
|
for (key in attrs) {
|
||||||
|
delete Kinetic.Tween.tweens[nodeId][key];
|
||||||
|
}
|
||||||
|
|
||||||
|
delete Kinetic.Tween.attrs[nodeId][thisId];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -61,5 +61,48 @@ Test.Modules.TWEEN = {
|
|||||||
test(Kinetic.Tween.attrs[circle._id][tween._id].x !== undefined, 'x should not be undefined');
|
test(Kinetic.Tween.attrs[circle._id][tween._id].x !== undefined, 'x should not be undefined');
|
||||||
test(Kinetic.Tween.attrs[circle._id][tween._id].y !== undefined, 'y should not be undefined');
|
test(Kinetic.Tween.attrs[circle._id][tween._id].y !== undefined, 'y should not be undefined');
|
||||||
|
|
||||||
|
},
|
||||||
|
'tween node': function(containerId) {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
|
||||||
|
var layer = new Kinetic.Layer();
|
||||||
|
|
||||||
|
var circle = new Kinetic.Circle({
|
||||||
|
x: 100,
|
||||||
|
y: stage.getHeight() / 2,
|
||||||
|
radius: 70,
|
||||||
|
fill: 'green',
|
||||||
|
stroke: 'blue',
|
||||||
|
strokeWidth: 4
|
||||||
|
});
|
||||||
|
|
||||||
|
layer.add(circle);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
|
||||||
|
var tween = new Kinetic.Tween({
|
||||||
|
node: circle,
|
||||||
|
duration: 0.2,
|
||||||
|
x: 200,
|
||||||
|
y: 100
|
||||||
|
}).play();
|
||||||
|
|
||||||
|
// start/diff object = attrs.nodeId.tweenId.attr
|
||||||
|
// tweenId = tweens.nodeId.attr
|
||||||
|
|
||||||
|
test(tween._id !== undefined, 'tween.play should return an instance of the tween');
|
||||||
|
test(Kinetic.Tween.tweens[circle._id].x === tween._id, 'circle should be in the tweens hash');
|
||||||
|
test(Kinetic.Tween.attrs[circle._id][tween._id] !== undefined, 'tween should be in the attrs hash');
|
||||||
|
|
||||||
|
tween.destroy();
|
||||||
|
|
||||||
|
test(Kinetic.Tween.tweens[circle._id].x === undefined, 'circle should not be in the tweens hash');
|
||||||
|
test(Kinetic.Tween.attrs[circle._id][tween._id] === undefined, 'tween should not be in the attrs hash');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
Reference in New Issue
Block a user