diff --git a/src/lib/setup/base.js b/src/lib/setup/base.js index 92fa11dc..6a85cbf8 100644 --- a/src/lib/setup/base.js +++ b/src/lib/setup/base.js @@ -272,18 +272,19 @@ export default (component, name) => { const deleteChildren = function (children) { for (let i = 0; i < children.length; i++) { if (!children[i]) return - if (Array.isArray(children[i])) { - deleteChildren(children[i]) - } else if (Object.getPrototypeOf(children[i]) === Object.prototype) { - Object.keys(children[i]).forEach((k) => { - if (children[i][k].destroy) { - children[i][k].destroy() - } - children[i][k] = null - }) - } else if (children[i].destroy) { + // call destroy when method is available on child + if (children[i].destroy && typeof children[i].destroy === 'function') { children[i].destroy() } + // recursively call deleteChildren when it's an object of items (happens when using a forloop construct) + else if (Object.getPrototypeOf(children[i]) === Object.prototype) { + deleteChildren(Object.values(children[i])) + } + // todo: this case may not be needed anymore + else if (Array.isArray(children[i])) { + deleteChildren(children[i]) + } + children[i] = null }