Skip to content

Commit

Permalink
revert (#4084)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio authored Mar 8, 2024
1 parent 28d1206 commit 2025817
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 43 deletions.
14 changes: 1 addition & 13 deletions packages/alpinejs/src/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,13 @@ export function interceptInit(callback) { initInterceptors.push(callback) }
export function initTree(el, walker = walk, intercept = () => {}) {
deferHandlingDirectives(() => {
walker(el, (el, skip) => {
if (el._x_inited) {
if (el._x_ignore) skip()

return
}

intercept(el, skip)

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

directives(el, el.attributes).forEach(handle => handle())

if (el._x_ignore) {
skip()
} else {
el._x_inited = true
}
el._x_ignore && skip()
})
})
}
Expand All @@ -106,7 +96,5 @@ export function destroyTree(root, walker = walk) {
walker(root, el => {
cleanupAttributes(el)
cleanupElement(el)

delete el._x_inited
})
}
1 change: 1 addition & 0 deletions packages/alpinejs/src/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function onMutate(mutations) {
for (let node of addedNodes) {
// If the node was eventually removed as part of one of his
// parent mutations, skip it
if (removedNodes.has(node)) continue
if (! node.isConnected) continue

delete node._x_ignoreSelf
Expand Down
30 changes: 0 additions & 30 deletions tests/cypress/integration/mutation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,36 +136,6 @@ test('can pause and queue mutations for later resuming/flushing',
}
)

test('add and move element are been initialized',
html`
<div x-data="{
foo: 0,
bar: 0,
test() {
container = document.createElement('div')
this.$root.appendChild(container)
alpineElement = document.createElement('span')
alpineElement.setAttribute('x-data', '{init() {this.bar++}}')
alpineElement.setAttribute('x-init', 'foo++')
container.appendChild(alpineElement)
container.removeChild(alpineElement)
container.appendChild(alpineElement)
}
}">
<span id="one" x-text="foo"></span>
<span id="two" x-text="bar"></span>
<button @click="test">Test</button>
</div>
`,
({ get }) => {
get('span#one').should(haveText('0'))
get('span#two').should(haveText('0'))
get('button').click()
get('span#one').should(haveText('1'))
get('span#two').should(haveText('1'))
}
)

test('does not initialise components twice when contained in multiple mutations',
html`
<div x-data="{
Expand Down

0 comments on commit 2025817

Please sign in to comment.