1
0
Fork 0
mirror of https://github.com/archtechx/wire-replace.git synced 2025-12-12 07:34:02 +00:00
wire-replace/index.js
2020-12-30 22:29:11 +01:00

18 lines
680 B
JavaScript

/**
* Add wire:replace functionality to Livewire.
*
* When wire:replace is applied to an element, the element's children will *always* be fully replaced rather than intelligently DOM-diffed.
* When wire:replace.self is applied to an element, the element itself (plus all of its children) will be
*/
export default ['element.updating', (from, to) => {
let attributes = Object.values(from.attributes);
if (attributes.filter(attribute => attribute.name === 'wire:replace').length) {
from.innerHTML = to.innerHTML;
}
if (attributes.filter(attribute => attribute.name === 'wire:replace.self').length) {
from.outerHTML = to.outerHTML;
}
}];