MCPcopy
hub / github.com/konvajs/konva / add

Function add

src/Container.ts:119–145  ·  view source on GitHub ↗

* add a child and children into container * @name Konva.Container#add * @method * @param {...Konva.Node} children * @returns {Container} * @example * layer.add(rect); * layer.add(shape1, shape2, shape3); * // empty arrays are accepted, though each individual child must be def

(...children: ChildType[])

Source from the content-addressed store, hash-verified

117 * layer.add(...shapes);
118 */
119 add(...children: ChildType[]) {
120 if (children.length === 0) {
121 return this;
122 }
123 if (children.length > 1) {
124 for (let i = 0; i < children.length; i++) {
125 this.add(children[i]);
126 }
127 return this;
128 }
129 const child = children[0];
130 if (child.getParent()) {
131 child.moveTo(this);
132 return this;
133 }
134 this._validateAdd(child);
135 child.index = this.getChildren().length;
136 child.parent = this;
137 child._clearCaches();
138 this.getChildren().push(child);
139 this._fire('add', {
140 child: child,
141 });
142 this._requestDraw();
143 // chainable
144 return this;
145 }
146 destroy() {
147 if (this.hasChildren()) {
148 this.destroyChildren();

Callers

nothing calls this directly

Calls 4

getParentMethod · 0.80
moveToMethod · 0.80
addMethod · 0.45
_validateAddMethod · 0.45

Tested by

no test coverage detected