Caleb Porzio преди 1 година
родител
ревизия
3196c6ac66
променени са 2 файла, в които са добавени 13 реда и са изтрити 18 реда
  1. 7 13
      packages/alpinejs/src/lifecycle.js
  2. 6 5
      packages/alpinejs/src/mutation.js

+ 7 - 13
packages/alpinejs/src/lifecycle.js

@@ -82,18 +82,13 @@ export function interceptInit(callback) { initInterceptors.push(callback) }
 export function initTree(el, walker = walk, intercept = () => {}) {
 export function initTree(el, walker = walk, intercept = () => {}) {
     deferHandlingDirectives(() => {
     deferHandlingDirectives(() => {
         walker(el, (el, skip) => {
         walker(el, (el, skip) => {
-            if (!el._x_isInit) {
-                intercept(el, skip)
-
-                initInterceptors.forEach(i => i(el, skip))
-                directives(el, el.attributes).forEach(handle => handle())
-            }
-
-            if (el._x_ignore) {
-                skip()
-            } else {
-                el._x_isInit = true
-            }
+            intercept(el, skip)
+
+            initInterceptors.forEach(i => i(el, skip))
+
+            directives(el, el.attributes).forEach(handle => handle())
+
+            el._x_ignore && skip()
         })
         })
     })
     })
 }
 }
@@ -102,6 +97,5 @@ export function destroyTree(root) {
     walk(root, el => {
     walk(root, el => {
         cleanupAttributes(el)
         cleanupAttributes(el)
         cleanupElement(el)
         cleanupElement(el)
-        delete el._x_isInit
     })
     })
 }
 }

+ 6 - 5
packages/alpinejs/src/mutation.js

@@ -119,8 +119,8 @@ function onMutate(mutations) {
         return
         return
     }
     }
 
 
-    let addedNodes = []
-    let removedNodes = []
+    let addedNodes = new Set
+    let removedNodes = new Set
     let addedAttributes = new Map
     let addedAttributes = new Map
     let removedAttributes = new Map
     let removedAttributes = new Map
 
 
@@ -128,8 +128,8 @@ function onMutate(mutations) {
         if (mutations[i].target._x_ignoreMutationObserver) continue
         if (mutations[i].target._x_ignoreMutationObserver) continue
 
 
         if (mutations[i].type === 'childList') {
         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') {
         if (mutations[i].type === 'attributes') {
@@ -171,10 +171,11 @@ function onMutate(mutations) {
         onAttributeAddeds.forEach(i => i(el, attrs))
         onAttributeAddeds.forEach(i => i(el, attrs))
     })
     })
 
 
+    console.log(removedNodes, addedNodes)
     for (let node of removedNodes) {
     for (let node of removedNodes) {
         // If an element gets moved on a page, it's registered
         // If an element gets moved on a page, it's registered
         // as both an "add" and "remove", so we want to skip those.
         // 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))
         onElRemoveds.forEach(i => i(node))