Created
October 16, 2020 02:42
-
-
Save ayamomiji/7809dd51915a80fe93aeb452d7f16662 to your computer and use it in GitHub Desktop.
Revisions
-
ayamomiji created this gist
Oct 16, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ <div x-data @remove='console.log($el, "removed")'></div> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ const observer = new MutationObserver(mutations => { for (const mutation of mutations) { if (mutation.type !== 'childList') continue mutation.removedNodes.forEach(node => { if (node.nodeType !== Node.ELEMENT_NODE) return [node, ...node.querySelectorAll('[\\@remove]')].forEach(node => { node.dispatchEvent(new CustomEvent('remove')) }) }) } }) observer.observe(document, { childList: true, subtree: true })