Skip to content

Commit

Permalink
replace set intersection with function as it is not in all browsers yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelWest22 committed Dec 20, 2024
1 parent a8efad7 commit 1d8b4ac
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/idiomorph.js
Original file line number Diff line number Diff line change
Expand Up @@ -1100,8 +1100,7 @@ var Idiomorph = (function () {
// places where tempNode may be just a Node, not an Element
function removeNode(tempNode, ctx) {
removeIdsFromConsideration(ctx, tempNode)
// @ts-ignore - use new set intersection feature
if (ctx.pantry && ctx.idMap.get(tempNode)?.intersection(ctx.persistentIds).size > 0 && tempNode instanceof Element) {
if (ctx.pantry && hasPersistentIdNodes(ctx, tempNode) && tempNode instanceof Element) {
moveToPantry(tempNode, ctx);
} else {
if (ctx.callbacks.beforeNodeRemoved(tempNode) === false) return;
Expand Down Expand Up @@ -1226,6 +1225,21 @@ var Idiomorph = (function () {
}
}

/**
*
* @param {MorphContext} ctx
* @param {Node} node
* @returns {boolean}
*/
function hasPersistentIdNodes(ctx, node) {
for (const id of ctx.idMap.get(node) || EMPTY_SET) {
if (ctx.persistentIds.has(id)) {
return true;
}
}
return false;
}

/**
*
* @param {MorphContext} ctx
Expand Down

0 comments on commit 1d8b4ac

Please sign in to comment.