garbage collecting empty arrays in _removeName method to free up space

This commit is contained in:
Eric Rowell
2012-06-02 00:39:17 -07:00
parent 1b333bc800
commit 9f243d4a2e
5 changed files with 45 additions and 25 deletions

32
dist/kinetic-core.js vendored
View File

@@ -1971,7 +1971,7 @@ Kinetic.Stage.prototype = {
return true;
}
else if(!isDragging && this.touchMove) {
else if(!isDragging && this.touchMove) {
shape._handleEvents('touchmove', evt);
return true;
}
@@ -2416,6 +2416,9 @@ Kinetic.Stage.prototype = {
nodes.splice(n, 1);
}
}
if(nodes.length === 0) {
this.names[node.attrs.name] = undefined;
}
}
}
},
@@ -2911,20 +2914,27 @@ Kinetic.Shape.prototype = {
context.lineJoin = this.attrs.lineJoin;
}
},
/**
* apply shadow. return true if shadow was applied
* and false if it was not
*/
_applyShadow: function() {
var context = this.getContext();
var s = this.attrs.shadow;
var aa = this.getAbsoluteAlpha();
var sa = this.attrs.shadow.alpha;
if(s.color !== undefined) {
context.globalAlpha = sa * aa;
context.shadowColor = s.color;
context.shadowBlur = s.blur;
context.shadowOffsetX = s.offset.x;
context.shadowOffsetY = s.offset.y;
this.appliedShadow = true;
return true;
if(s !== undefined) {
var aa = this.getAbsoluteAlpha();
var sa = this.attrs.shadow.alpha;
if(sa !== undefined && s.color !== undefined) {
context.globalAlpha = sa * aa;
context.shadowColor = s.color;
context.shadowBlur = s.blur;
context.shadowOffsetX = s.offset.x;
context.shadowOffsetY = s.offset.y;
this.appliedShadow = true;
return true;
}
}
return false;

File diff suppressed because one or more lines are too long

View File

@@ -264,20 +264,27 @@ Kinetic.Shape.prototype = {
context.lineJoin = this.attrs.lineJoin;
}
},
/**
* apply shadow. return true if shadow was applied
* and false if it was not
*/
_applyShadow: function() {
var context = this.getContext();
var s = this.attrs.shadow;
var aa = this.getAbsoluteAlpha();
var sa = this.attrs.shadow.alpha;
if(s.color !== undefined) {
context.globalAlpha = sa * aa;
context.shadowColor = s.color;
context.shadowBlur = s.blur;
context.shadowOffsetX = s.offset.x;
context.shadowOffsetY = s.offset.y;
this.appliedShadow = true;
return true;
if(s !== undefined) {
var aa = this.getAbsoluteAlpha();
var sa = this.attrs.shadow.alpha;
if(sa !== undefined && s.color !== undefined) {
context.globalAlpha = sa * aa;
context.shadowColor = s.color;
context.shadowBlur = s.blur;
context.shadowOffsetX = s.offset.x;
context.shadowOffsetY = s.offset.y;
this.appliedShadow = true;
return true;
}
}
return false;

View File

@@ -493,7 +493,7 @@ Kinetic.Stage.prototype = {
return true;
}
else if(!isDragging && this.touchMove) {
else if(!isDragging && this.touchMove) {
shape._handleEvents('touchmove', evt);
return true;
}
@@ -938,6 +938,9 @@ Kinetic.Stage.prototype = {
nodes.splice(n, 1);
}
}
if(nodes.length === 0) {
this.names[node.attrs.name] = undefined;
}
}
}
},

View File

@@ -581,7 +581,7 @@ Test.prototype.tests = {
parent.remove(nodes[0]);
test(stage.ids.myCircle === undefined, 'circle still in hash');
test(stage.names.myRect[0] === undefined, 'rect still in hash');
test(stage.names.myRect === undefined, 'rect still in hash');
},
'STAGE - set shape and layer alpha to 0.5': function(containerId) {