mirror of
https://github.com/archtechx/wire-replace.git
synced 2025-12-11 23:24:03 +00:00
18 lines
680 B
JavaScript
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;
|
|
}
|
|
}];
|