diff --git a/src/core/Emitter.js b/src/core/Emitter.js index d5d50e87..8087f7da 100644 --- a/src/core/Emitter.js +++ b/src/core/Emitter.js @@ -125,7 +125,7 @@ var Emitter = { if (func) func.call(this, type); } - } + } } }, diff --git a/src/item/Item.js b/src/item/Item.js index 07d1fc70..933f860b 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -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. diff --git a/test/tests/Layer.js b/test/tests/Layer.js index 92b43678..eee463a4 100644 --- a/test/tests/Layer.js +++ b/test/tests/Layer.js @@ -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); +});