diff --git a/src/Container.ts b/src/Container.ts index efd4c2f5..c1d80130 100644 --- a/src/Container.ts +++ b/src/Container.ts @@ -83,7 +83,6 @@ export abstract class Container< this.getChildren().forEach((child) => { // reset parent to prevent many _setChildrenIndices calls child.parent = null; - child.index = 0; child.remove(); }); this.children = []; @@ -100,7 +99,6 @@ export abstract class Container< this.getChildren().forEach((child) => { // reset parent to prevent many _setChildrenIndices calls child.parent = null; - child.index = 0; child.destroy(); }); this.children = []; @@ -139,7 +137,6 @@ export abstract class Container< return this; } this._validateAdd(child); - child.index = this.getChildren().length; child.parent = this; child._clearCaches(); this.getChildren().push(child); @@ -336,12 +333,6 @@ export abstract class Container< node._clearSelfAndDescendantCache(attr); }); } - _setChildrenIndices() { - this.children?.forEach(function (child, n) { - child.index = n; - }); - this._requestDraw(); - } drawScene(can?: SceneCanvas, top?: Node, bufferCanvas?: SceneCanvas) { var layer = this.getLayer()!, canvas = can || (layer && layer.getCanvas()), diff --git a/src/Node.ts b/src/Node.ts index 281601c7..90368fb2 100644 --- a/src/Node.ts +++ b/src/Node.ts @@ -145,7 +145,6 @@ export abstract class Node { [index: string]: Array<{ name: string; handler: Function }>; } = {}; attrs: any = {}; - index = 0; _allEventListeners: null | Array = null; parent: Container | null = null; _cache: Map = new Map(); @@ -172,6 +171,17 @@ export abstract class Node { // all change event listeners are attached to the prototype } + get index() { + if (this.parent) { + return this.parent.children.indexOf(this); + } + return -1; + } + + set index(_val: number) { + + } + hasChildren() { return false; } @@ -854,7 +864,6 @@ export abstract class Node { if (parent && parent.children) { parent.children.splice(this.index, 1); - parent._setChildrenIndices(); this.parent = null; } } @@ -1361,7 +1370,6 @@ export abstract class Node { if (index < len - 1) { this.parent.children.splice(index, 1); this.parent.children.push(this); - this.parent._setChildrenIndices(); return true; } return false; @@ -1382,7 +1390,6 @@ export abstract class Node { if (index < len - 1) { this.parent.children.splice(index, 1); this.parent.children.splice(index + 1, 0, this); - this.parent._setChildrenIndices(); return true; } return false; @@ -1402,7 +1409,6 @@ export abstract class Node { if (index > 0) { this.parent.children.splice(index, 1); this.parent.children.splice(index - 1, 0, this); - this.parent._setChildrenIndices(); return true; } return false; @@ -1422,7 +1428,6 @@ export abstract class Node { if (index > 0) { this.parent.children.splice(index, 1); this.parent.children.unshift(this); - this.parent._setChildrenIndices(); return true; } return false; @@ -1444,7 +1449,6 @@ export abstract class Node { var index = this.index; this.parent.children.splice(index, 1); this.parent.children.splice(zIndex, 0, this); - this.parent._setChildrenIndices(); return this; } /**