* 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[])
| 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(); |
nothing calls this directly
no test coverage detected