Skip to content

Instantly share code, notes, and snippets.

@gbakernet
Created November 18, 2010 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gbakernet/704663 to your computer and use it in GitHub Desktop.
Save gbakernet/704663 to your computer and use it in GitHub Desktop.
PUBSUB on the back of jquery events
(function($){
$.pubsub = (function(){
var mule = $({});
return {
subscribe:function(key, fn){
//Normalise
mule.bind(key, function(e, data){
fn.apply(null, [data]);
});
},
publish:function(key, data){
mule.trigger(key, data);
},
unsubscribe:function(key){
mule.unbind(key);
}
};
}());
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment