Skip to content

Instantly share code, notes, and snippets.

@beckettkev
Created May 13, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beckettkev/b066b7ac7b70641fe25c to your computer and use it in GitHub Desktop.
Save beckettkev/b066b7ac7b70641fe25c to your computer and use it in GitHub Desktop.
$.SubscriptionEvent = (function () {
var subscribers = {};
return function (id) {
var callbacks, sub = id && subscribers[id];
if (!sub) {
callbacks = jQuery.Callbacks();
sub = {
publish: callbacks.fire,
subscribe: callbacks.add,
unsubscribe: callbacks.remove
};
if (id) {
subscribers[id] = sub;
}
}
return sub;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment