Created
April 10, 2012 10:51
-
-
Save rozmiarek/2350398 to your computer and use it in GitHub Desktop.
PubSub based on jQuery.Callback
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
define(['jquery'], function ($) { | |
var topics = {}, | |
topic = function (id) { | |
var fn = this.toString(), | |
args = [].slice.call(arguments, 1); | |
(topics[id] = topics[id] || $.Callbacks())[fn].apply(null, args); | |
}; | |
return { | |
pub: function () { topic.apply('fire', arguments); }, | |
sub: function () { topic.apply('add', arguments); }, | |
unsub: function () { topic.apply('remove', arguments); } | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment