Skip to content

Instantly share code, notes, and snippets.

@artursopelnik
Created July 19, 2018 10:22
Show Gist options
  • Save artursopelnik/3955e3d42bfcacbec941066110c0a19b to your computer and use it in GitHub Desktop.
Save artursopelnik/3955e3d42bfcacbec941066110c0a19b to your computer and use it in GitHub Desktop.
jQuery Tiny Pub/Sub - v0.8
/* jQuery Tiny Pub/Sub - v0.8 - 07/19/2018
* 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);
};
$.once = function (args, callback) {
return $.subscribe(args, callback, function () {
callback();
$.unsubscribe(args);
});
};
$.publish = function() {
o.trigger.apply(o, arguments);
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment