Skip to content

Instantly share code, notes, and snippets.

@TrevorJTClarke
Created July 6, 2016 21:07
Show Gist options
  • Save TrevorJTClarke/4378ab0fcacae3e6ccbbf3420357c9bd to your computer and use it in GitHub Desktop.
Save TrevorJTClarke/4378ab0fcacae3e6ccbbf3420357c9bd to your computer and use it in GitHub Desktop.
A quick reminder example of MutationObserver
/**
* 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