mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
When removing a child, set key "parent" to null, don't delete it
Structural changes to objects are relatively more expensive and harder to optimize for modern JavaScript compilers, compared to just changing object's key values. The parent property of nodes is already set to null now, as part constructing the object. Setting it back to null on removal / destroy of objects is more consistent and a tiny little bit more efficient.
This commit is contained in:
parent
6b1cf1d306
commit
15e7477e81
@ -66,7 +66,7 @@ export abstract class Container extends Node {
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
child = children[i];
|
||||
// reset parent to prevent many _setChildrenIndices calls
|
||||
delete child.parent;
|
||||
child.parent = null;
|
||||
child.index = 0;
|
||||
child.remove();
|
||||
}
|
||||
@ -85,7 +85,7 @@ export abstract class Container extends Node {
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
child = children[i];
|
||||
// reset parent to prevent many _setChildrenIndices calls
|
||||
delete child.parent;
|
||||
child.parent = null;
|
||||
child.index = 0;
|
||||
child.destroy();
|
||||
}
|
||||
|
@ -719,7 +719,7 @@ export abstract class Node {
|
||||
if (parent && parent.children) {
|
||||
parent.children.splice(this.index, 1);
|
||||
parent._setChildrenIndices();
|
||||
delete this.parent;
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
// every cached attr that is calculated via node tree
|
||||
|
Loading…
Reference in New Issue
Block a user