Skip to content

Instantly share code, notes, and snippets.

@1337
Created November 4, 2012 17:13
Show Gist options
  • Save 1337/4012640 to your computer and use it in GitHub Desktop.
Save 1337/4012640 to your computer and use it in GitHub Desktop.
/*
PubSub by github.com/1337
GPLv3 (if you don't ask) or MIT (if you ask first)
what this does depends on the func signature.
$.pubSub(name);
calls all funcs under this name with default params
$.pubSub(name, params);
calls all funcs under this name with params
$.pubSub(name, params, callback);
registers a new function (callback) with default params (params)
under the name (name)
$.pubSub.reset() removes all callbacks.
$.pubSub.reset(name) removes all callbacks under that name.
This hooks itself onto a $ object no matter what it is. Hey, I don't care!
*/
(function(a,b){if(a[b])return;var c={},d=function(a,b,e){if(!a)return;if(b&&e){c[a]=c[a]||[],c[a].push([e,b]);return}d.callback(a,b)()};d.callback=function(a,b){return function(){var d=c[a]||[];for(var e=0;e<d.length;e++)d[e][0].apply(null,b||d[e][1]||[])}},d.hooks=function(){return c},d.reset=d.reset||function(a){a?c[a]=[]:c={}},a[b]=d})($||{},"pubSub")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment