Skip to content

Commit

Permalink
convert some if statements to type assertions.
Browse files Browse the repository at this point in the history
  • Loading branch information
botandrose-machine committed Feb 15, 2025
1 parent b96e57a commit f33e9d7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/idiomorph.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,11 @@ var Idiomorph = (function () {
*/
function createNode(oldParent, newChild, insertionPoint, ctx) {
if (ctx.callbacks.beforeNodeAdded(newChild) === false) return null;
if (ctx.idMap.has(newChild) && newChild instanceof Element) {
if (ctx.idMap.has(newChild)) {
// node has children with ids with possible state so create a dummy elt of same type and apply full morph algorithm
const newEmptyChild = document.createElement(newChild.tagName);
const newEmptyChild = document.createElement(
/** @type {Element} */ (newChild).tagName,
);
oldParent.insertBefore(newEmptyChild, insertionPoint);
morphNode(newEmptyChild, newChild, ctx);
ctx.callbacks.afterNodeAdded(newEmptyChild);
Expand Down Expand Up @@ -498,7 +500,7 @@ var Idiomorph = (function () {
*/
function removeNode(ctx, node) {
// are we going to id set match this later?
if (ctx.idMap.has(node) && node instanceof Element) {
if (ctx.idMap.has(node)) {
// skip callbacks and move to pantry
moveBefore(ctx.pantry, node, null);
} else {
Expand Down

0 comments on commit f33e9d7

Please sign in to comment.