Skip to content

Commit

Permalink
Merge branch 'Omerlo-Technologies/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed Jan 21, 2024
2 parents 35f9ac1 + 3196c6a commit cb1e3ac
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions packages/alpinejs/src/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,17 @@ function onMutate(mutations) {
return
}

let addedNodes = []
let removedNodes = []
let addedNodes = new Set
let removedNodes = new Set
let addedAttributes = new Map
let removedAttributes = new Map

for (let i = 0; i < mutations.length; i++) {
if (mutations[i].target._x_ignoreMutationObserver) continue

if (mutations[i].type === 'childList') {
mutations[i].addedNodes.forEach(node => node.nodeType === 1 && addedNodes.push(node))
mutations[i].removedNodes.forEach(node => node.nodeType === 1 && removedNodes.push(node))
mutations[i].addedNodes.forEach(node => node.nodeType === 1 && addedNodes.add(node))
mutations[i].removedNodes.forEach(node => node.nodeType === 1 && removedNodes.add(node))
}

if (mutations[i].type === 'attributes') {
Expand Down Expand Up @@ -171,10 +171,11 @@ function onMutate(mutations) {
onAttributeAddeds.forEach(i => i(el, attrs))
})

console.log(removedNodes, addedNodes)
for (let node of removedNodes) {
// If an element gets moved on a page, it's registered
// as both an "add" and "remove", so we want to skip those.
if (addedNodes.includes(node)) continue
if (addedNodes.has(node)) continue

onElRemoveds.forEach(i => i(node))

Expand All @@ -194,10 +195,6 @@ function onMutate(mutations) {
node._x_ignore = true
})
for (let node of addedNodes) {
// If an element gets moved on a page, it's registered
// as both an "add" and "remove", so we want to skip those.
if (removedNodes.includes(node)) continue

// If the node was eventually removed as part of one of his
// parent mutations, skip it
if (! node.isConnected) continue
Expand Down

0 comments on commit cb1e3ac

Please sign in to comment.