From 65b76a277649b534ae4160b5b856ed44ac9d5773 Mon Sep 17 00:00:00 2001 From: Alexis Fontaine Date: Sat, 14 Jan 2023 17:07:01 +0100 Subject: [PATCH] Handle adding empty arrays to a container --- src/Container.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Container.ts b/src/Container.ts index 69fb545a3..a6abfed63 100644 --- a/src/Container.ts +++ b/src/Container.ts @@ -109,22 +109,27 @@ export abstract class Container< * add a child and children into container * @name Konva.Container#add * @method - * @param {...Konva.Node} child + * @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 defined + * layer.add(...shapes); * // remember to redraw layer if you changed something * layer.draw(); */ add(...children: ChildType[]) { - if (arguments.length > 1) { - for (var i = 0; i < arguments.length; i++) { - this.add(arguments[i]); + if (children.length === 0) { + return this; + } + if (children.length > 1) { + for (var i = 0; i < children.length; i++) { + this.add(children[i]); } return this; } - var child = children[0]; + const child = children[0]; if (child.getParent()) { child.moveTo(this); return this;