refined global object temp nodes has removal when removing nodes from container. Also added another unit test

This commit is contained in:
Eric Rowell 2012-04-08 17:50:46 -07:00
parent 2035d188c8
commit 4f36b27199
4 changed files with 44 additions and 6 deletions

View File

@ -873,8 +873,10 @@ Kinetic.Container.prototype = {
_remove: function(child) {
if(this.children[child.index]._id == child._id) {
var stage = this.getStage();
stage._removeId(child);
stage._removeName(child);
if(stage !== undefined) {
stage._removeId(child);
stage._removeName(child);
}
var go = Kinetic.GlobalObject;
for(var n = 0; n < go.tempNodes.length; n++) {

File diff suppressed because one or more lines are too long

View File

@ -34,8 +34,10 @@ Kinetic.Container.prototype = {
_remove: function(child) {
if(this.children[child.index]._id == child._id) {
var stage = this.getStage();
stage._removeId(child);
stage._removeName(child);
if(stage !== undefined) {
stage._removeId(child);
stage._removeName(child);
}
var go = Kinetic.GlobalObject;
for(var n = 0; n < go.tempNodes.length; n++) {

View File

@ -381,6 +381,40 @@ Test.prototype.tests = {
test(stage.ids.myCircle === undefined, 'circle still in hash');
test(stage.names.myRect[0] === undefined, 'rect still in hash');
},
'STAGE - remove shape without adding its parent to stage': function(containerId) {
var stage = new Kinetic.Stage({
container: containerId,
width: 578,
height: 200
});
var layer = new Kinetic.Layer();
var circle = new Kinetic.Circle({
x: stage.getWidth() / 2,
y: stage.getHeight() / 2,
radius: 70,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
id: 'myCircle'
});
var go = Kinetic.GlobalObject;
test(go.tempNodes.length === 0, 'shouldn\'t be nodes in the tempNdoes array');
layer.add(circle);
var node = stage.get('#myCircle');
test(node === undefined, 'node should be undefined');
test(go.tempNodes.length === 1, 'tempNodes array should have one node');
layer.remove(circle);
test(go.tempNodes.length === 0, 'shouldn\'t be nodes in the tempNdoes array');
},
'STAGE - remove layer with shape': function(containerId) {
var stage = new Kinetic.Stage({