Merge pull request #1133 from sapics/remove-layer

Fix to remove named layer
This commit is contained in:
Jürg Lehni 2016-08-07 15:55:17 +02:00 committed by GitHub
commit e3dae5f96f
3 changed files with 18 additions and 4 deletions

View file

@ -125,7 +125,7 @@ var Emitter = {
if (func)
func.call(this, type);
}
}
}
}
},

View file

@ -2549,6 +2549,9 @@ new function() { // Injection scope for hit-test functions shared with project
project = this._project,
index = this._index;
if (owner) {
// Handle named children separately from index:
if (this._name)
this._removeNamed();
// Handle index separately from owner: There are situations where
// the item is already removed from its list through Base.splice()
// and index set to undefined, but the owner is still set,
@ -2560,9 +2563,6 @@ new function() { // Injection scope for hit-test functions shared with project
|| this.getPreviousSibling();
Base.splice(owner._children, null, index, 1);
}
// Handle named children separately from index:
if (this._name)
this._removeNamed();
this._installEvents(false);
// Notify self of the insertion change. We only need this
// notification if we're tracking changes for now.

View file

@ -125,3 +125,17 @@ test('addChild / appendBottom / nesting', function() {
&& project.layers[1] == firstLayer;
}, true);
});
test('remove', function(){
var layer1 = new Layer({name: 'test-layer'});
var layer2 = new Layer({name: 'test-layer'});
var removeCount = 0;
while (project.layers['test-layer']) {
project.layers['test-layer'].remove();
++removeCount;
if (removeCount > 2) break;
}
equals(function(){
return removeCount;
}, 2);
});