-
-
Save vladkotu/1327219 to your computer and use it in GitHub Desktop.
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
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
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011 | |
* http://benalman.com/ | |
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */ | |
(function($) { | |
var o = $({}); | |
$.subscribe = function() { | |
o.on.apply(o, arguments); | |
}; | |
$.unsubscribe = function() { | |
o.off.apply(o, arguments); | |
}; | |
$.publish = function() { | |
o.trigger.apply(o, arguments); | |
}; | |
$.multiarmed = function (a){ | |
var events = a.events, | |
callback = a.callback, | |
stored = {}, | |
fired = 0, | |
slice = Array.prototype.slice; | |
return function (e){ | |
var idxE = $.inArray(e.type, events), | |
type = e.type; | |
if ( -1 === idxE ) return true; | |
stored[type] = slice.call(arguments, 1); | |
delete events[idxE]; | |
fired += 1; | |
if (fired === events.length){ | |
callback.call(a.context || {}, stored); | |
} | |
}; | |
}; | |
}(jQuery)); |
Author
vladkotu
commented
Oct 31, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment