Created
November 4, 2012 17:13
-
-
Save 1337/4012640 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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