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:
parent
fa4ad79d89
commit
62eb081a13
2 changed files with 4 additions and 11 deletions
|
|
@ -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))
|
- 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: 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: 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
|
#### News
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -643,22 +643,14 @@ module.exports = function($window) {
|
||||||
checkState(vnode, original)
|
checkState(vnode, original)
|
||||||
onremove(vnode)
|
onremove(vnode)
|
||||||
if (vnode.dom) {
|
if (vnode.dom) {
|
||||||
|
var parent = vnode.dom.parentNode
|
||||||
var count = vnode.domSize || 1
|
var count = vnode.domSize || 1
|
||||||
if (count > 1) {
|
while (--count) parent.removeChild(vnode.dom.nextSibling)
|
||||||
var dom = vnode.dom
|
parent.removeChild(vnode.dom)
|
||||||
while (--count) {
|
|
||||||
removeNodeFromDOM(dom.nextSibling)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
removeNodeFromDOM(vnode.dom)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function removeNodeFromDOM(node) {
|
|
||||||
var parent = node.parentNode
|
|
||||||
if (parent != null) parent.removeChild(node)
|
|
||||||
}
|
|
||||||
function onremove(vnode) {
|
function onremove(vnode) {
|
||||||
if (vnode.attrs && typeof vnode.attrs.onremove === "function") callHook.call(vnode.attrs.onremove, vnode)
|
if (vnode.attrs && typeof vnode.attrs.onremove === "function") callHook.call(vnode.attrs.onremove, vnode)
|
||||||
if (typeof vnode.tag !== "string") {
|
if (typeof vnode.tag !== "string") {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue