Skip to content

Commit a31fa69

Browse files
committed
Move back to function
1 parent 49bd318 commit a31fa69

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/diff/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { BaseComponent, getDomSibling } from '../component';
1313
import { Fragment } from '../create-element';
1414
import { diffChildren } from './children';
1515
import { setProperty } from './props';
16-
import { assign, isArray, slice } from '../util';
16+
import { assign, isArray, removeNode, slice } from '../util';
1717
import options from '../options';
1818

1919
/**
@@ -346,8 +346,7 @@ export function diff(
346346
newVNode._dom = oldDom;
347347
} else {
348348
for (let i = excessDomChildren.length; i--; ) {
349-
const child = excessDomChildren[i];
350-
if (child) child.remove();
349+
removeNode(excessDomChildren[i]);
351350
}
352351
}
353352
} else {
@@ -589,8 +588,7 @@ function diffElementNodes(
589588
// Remove children that are not part of any vnode.
590589
if (excessDomChildren != NULL) {
591590
for (i = excessDomChildren.length; i--; ) {
592-
const child = excessDomChildren[i];
593-
if (child) child.remove();
591+
removeNode(excessDomChildren[i]);
594592
}
595593
}
596594
}
@@ -689,8 +687,8 @@ export function unmount(vnode, parentVNode, skipRemove) {
689687
}
690688
}
691689

692-
if (!skipRemove && vnode._dom != null && vnode._dom.parentNode) {
693-
vnode._dom.remove();
690+
if (!skipRemove) {
691+
removeNode(vnode._dom);
694692
}
695693

696694
vnode._component = vnode._parent = vnode._dom = UNDEFINED;

src/util.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ export function assign(obj, props) {
1515
for (let i in props) obj[i] = props[i];
1616
return /** @type {O & P} */ (obj);
1717
}
18+
19+
/**
20+
* Remove a child node from its parent if attached.
21+
* @param {import('./internal').PreactElement | null} node The node to remove
22+
*/
23+
export function removeNode(node) {
24+
if (node && node.parentNode) node.remove();
25+
}

0 commit comments

Comments
 (0)