Skip to content

Commit

Permalink
move everything to lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Matsa59 committed Jan 19, 2024
1 parent 9cfc4f7 commit c68aba0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
14 changes: 8 additions & 6 deletions packages/alpinejs/src/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,17 @@ export function interceptInit(callback) { initInterceptors.push(callback) }
export function initTree(el, walker = walk, intercept = () => {}) {
deferHandlingDirectives(() => {
walker(el, (el, skip) => {
intercept(el, skip)
if (!el._x_isInit) {
intercept(el, skip)

initInterceptors.forEach(i => i(el, skip))

directives(el, el.attributes).forEach(handle => handle())
initInterceptors.forEach(i => i(el, skip))
directives(el, el.attributes).forEach(handle => handle())
}

if (el._x_ignore) {
skip()
skip()
} else {
el._x_isInit = true
el._x_isInit = true
}
})
})
Expand All @@ -101,5 +102,6 @@ export function destroyTree(root) {
walk(root, el => {
cleanupAttributes(el)
cleanupElement(el)
delete el._x_isInit
})
}
5 changes: 0 additions & 5 deletions packages/alpinejs/src/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,10 @@ function onMutate(mutations) {
node._x_ignore = true
})
for (let node of addedNodes) {
// If the node is already init, it means it's a move operation
if (node._x_isInit) continue

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

node._x_isInit = true

delete node._x_ignoreSelf
delete node._x_ignore
onElAddeds.forEach(i => i(node))
Expand Down

0 comments on commit c68aba0

Please sign in to comment.