Skip to content

Commit

Permalink
Merge pull request #87 from suresh-gangumalla/fix/enable-children-com…
Browse files Browse the repository at this point in the history
…p-to-destroy

Destroy hook in children components not invoked
  • Loading branch information
michielvandergeest authored Apr 18, 2024
2 parents 1b200d4 + c5ccbb6 commit 206240f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/lib/setup/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,15 @@ 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 (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]))
}

children[i] = null
}

Expand Down
7 changes: 0 additions & 7 deletions src/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,6 @@ const removeView = async (route, view, transition) => {
if (route.options && route.options.keepAlive === true) {
cacheMap.set(route, { view: view, focus: previousFocus })
} else {
// remove and cleanup
for (let i = 0; i < view[symbols.children].length; i++) {
// if (view[symbols.children][i] && view[symbols.children][i].destroy) {
// view[symbols.children][i].destroy()
view[symbols.children][i] = null
// }
}
view.destroy()
view = null
}
Expand Down

0 comments on commit 206240f

Please sign in to comment.