Simplify element removal to save a few bytes

It's also a minor peephole optimization, but I saw bigger size wins, so
I'm citing that.
This commit is contained in:
Isiah Meadows 2018-09-20 15:12:59 -04:00
parent fa4ad79d89
commit 62eb081a13
2 changed files with 4 additions and 11 deletions

View file

@ -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

View file

@ -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") {