Skip to content

Commit

Permalink
Allow request to not morph the children but instead emit an event to …
Browse files Browse the repository at this point in the history
…its children using a selector
  • Loading branch information
Sjors Baltus committed Nov 25, 2021
1 parent 3a96f28 commit 69403ae
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions javascript/elements/updates_for_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,27 @@ export default class UpdatesForElement extends SubscribingElement {
html: fragments[i],
permanentAttributeName: 'data-ignore-updates'
}
dispatch(blocks[i], 'cable-ready:before-update', operation)
morphdom(blocks[i], fragments[i], {
childrenOnly: true,
onBeforeElUpdated: shouldMorph(operation),
onElUpdated: _ => {
blocks[i].removeAttribute('updating')
dispatch(blocks[i], 'cable-ready:after-update', operation)
assignFocus(operation.focusSelector)
}
})

if (!blocks[i].dataset.ignoreMorph) {
dispatch(blocks[i], 'cable-ready:before-update', operation)
morphdom(blocks[i], fragments[i], {
childrenOnly: true,
onBeforeElUpdated: shouldMorph(operation),
onElUpdated: _ => {
blocks[i].removeAttribute('updating')
console.warn('AFTER UPDATING', blocks[i])
dispatch(blocks[i], 'cable-ready:after-update', operation)
assignFocus(operation.focusSelector)
}
})
}

if (blocks[i].dataset.afterUpdateEventSelector) {
const elements = blocks[i].querySelectorAll(blocks[i].dataset.afterUpdateEventSelector);
elements.forEach(element => {
dispatch(element, 'cable-ready:after-update', operation);
});
}
}
}

Expand Down

0 comments on commit 69403ae

Please sign in to comment.