Skip to content

Instantly share code, notes, and snippets.

@rozmiarek
Created April 10, 2012 10:51
Show Gist options
  • Save rozmiarek/2350398 to your computer and use it in GitHub Desktop.
Save rozmiarek/2350398 to your computer and use it in GitHub Desktop.
PubSub based on jQuery.Callback
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