Skip to content

Instantly share code, notes, and snippets.

@roperzh
Created July 13, 2014 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roperzh/5c5059eb1122717863a1 to your computer and use it in GitHub Desktop.
Save roperzh/5c5059eb1122717863a1 to your computer and use it in GitHub Desktop.
Mutation observers and Essential.js
// -------------------------------------------
// 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