Created
July 13, 2014 15:26
-
-
Save roperzh/5c5059eb1122717863a1 to your computer and use it in GitHub Desktop.
Mutation observers and Essential.js
This file contains 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
// ------------------------------------------- | |
// Mutation observers applied | |
// ------------------------------------------- | |
Ui.Observable = Essential.Behavior.extend({ | |
config: { | |
attributes: true, | |
childList: true, | |
characterData: true | |
}, | |
init: function() { | |
this.observer = new MutationObserver(this.observerFunction.bind(this)); | |
this.observe(); | |
}, | |
observe: function() { | |
this.observer.observe(this.el, this.config); | |
}, | |
disconnect: function() { | |
this.observer.disconnect(); | |
}, | |
observerFunction: function(mutations) { | |
mutations.forEach(function(mutation) { | |
if(typeof this[mutation.type] === "function") { | |
this[mutation.type](mutation) | |
} | |
}.bind(this)); | |
} | |
}); | |
Ui.ChildObserver = Ui.Observable.extend({ | |
childList: function(e) { | |
console.log("yay!", e); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment