Skip to content

Instantly share code, notes, and snippets.

@hafriedlander
Created June 6, 2012 03:02
Show Gist options
  • Save hafriedlander/2879591 to your computer and use it in GitHub Desktop.
Save hafriedlander/2879591 to your computer and use it in GitHub Desktop.
Possible remote event binding for Entwine.js
/*
Old style. Problems: onmatch is slow. Leaks memory, because there's a reference from window to this node, and window exists forever, so that reference holds this DOM node out of the garbage once it's removed from the document.
*/
$('.node').entwine({
onmatch: function(){
var self = this;
$(window).bind('load', function(){ self.initialise(); });
},
initialise: function(){
}
});
/*
New method. Uses event delegation, so immediately active. By centralizing logic, hopefully eliminates memory leaks.
*/
$('.node').entwine({
initialise: $.entwine.delegate(window, 'load', function(){
}),
myParentHasChanged: $.entwine.delegate(function(){ return this.parent(); }, 'change', function(){
})
});
@hafriedlander
Copy link
Author

Sort of. They're real functions, and can be overloaded, called with _super, etc. It's up to the dev to pick a good key that's explanatory & not confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment