Created
July 6, 2016 21:07
-
-
Save TrevorJTClarke/4378ab0fcacae3e6ccbbf3420357c9bd to your computer and use it in GitHub Desktop.
A quick reminder example of MutationObserver
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 characters
/** | |
* MutationObserver Example | |
* | |
* A quick reminder for later use | |
*/ | |
// prolly do this? | |
window.MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver | |
module.exports = (function () { | |
let elem = 'custom-element' | |
// TODO: make listen to all | |
let target = document.querySelector(elem) | |
const config = { | |
attributes: true // this is to watch for attribute changes. | |
} | |
function template(data) { | |
return ` | |
<title>${data.title}</title> | |
` | |
} | |
// create an observer instance | |
var observer = new MutationObserver(function (mutation) { | |
console.log('mutation', mutation) | |
// template(mutation) | |
}) | |
observer.observe(target, config) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment