diff --git a/docs/change-log.md b/docs/change-log.md index b4c750b6..a5a53a20 100644 --- a/docs/change-log.md +++ b/docs/change-log.md @@ -29,6 +29,7 @@ - stream: when a stream conditionally returns HALT, dependant stream will also end ([#2200](https://github.com/MithrilJS/mithril.js/pull/2200)) - render: remove some redundancy within the component initialization code ([#2213](https://github.com/MithrilJS/mithril.js/pull/2213)) - render: Align custom elements to work like normal elements, minus all the HTML-specific magic. ([#2221](https://github.com/MithrilJS/mithril.js/pull/2221)) +- render: simplify component removal ([#2214](https://github.com/MithrilJS/mithril.js/pull/2214)) #### News diff --git a/render/render.js b/render/render.js index c05cfe1b..260a7766 100644 --- a/render/render.js +++ b/render/render.js @@ -643,22 +643,14 @@ module.exports = function($window) { checkState(vnode, original) onremove(vnode) if (vnode.dom) { + var parent = vnode.dom.parentNode var count = vnode.domSize || 1 - if (count > 1) { - var dom = vnode.dom - while (--count) { - removeNodeFromDOM(dom.nextSibling) - } - } - removeNodeFromDOM(vnode.dom) + while (--count) parent.removeChild(vnode.dom.nextSibling) + parent.removeChild(vnode.dom) } } } } - function removeNodeFromDOM(node) { - var parent = node.parentNode - if (parent != null) parent.removeChild(node) - } function onremove(vnode) { if (vnode.attrs && typeof vnode.attrs.onremove === "function") callHook.call(vnode.attrs.onremove, vnode) if (typeof vnode.tag !== "string") {