Skip to content

Instantly share code, notes, and snippets.

@shawnbierman
Created December 22, 2010 14:31
Show Gist options
  • Save shawnbierman/751581 to your computer and use it in GitHub Desktop.
Save shawnbierman/751581 to your computer and use it in GitHub Desktop.
have only one object unsubscribe.
// get xml file & publish
km.core = {
url: 'someDir/someFile',
fetch: $.get(url, function(xml) {
$.publish('xmlFetch', [xml]);
})
};
// subscribe to xml file and do stuff
km.widget.edVolGraph = {
handle: 'undefined',
load: function(location) {
km.widget.edVolGraph.handle = $.subscribe('xmlFetch', function() {
// do stuff
});
}
};
km.core.fetch(); // publish
km.widget.edVolGraph.load('south'); // subscribe
km.widget.edVolGraph.load('north'); // subscribe
$.unsubscribe(km.widget.edVolGraph.handle); // unsubscribes both!
// if a user wants to kill just one of the widgets
// how can you unsubscribe that one widget without
// unsubscribing the other
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment