UNPKG

jupiter

Version:

Simple, minimal & dependency-free JavaScript Publish/Subscribe

6 lines 1.71 kB
/** * JupiterJS * MIT License (http://honyovk.com/mit.txt). * Version 1.3.0 */ (function(n,t){return"function"==typeof define&&define.amd?(define(function(){return t.call(n)}),void 0):"undefined"!=typeof module&&module.exports?(module.exports=t.call(n),void 0):("undefined"!=typeof window&&(window.jupiter=t.call(n)),void 0)})(this,function(){function n(n,t){return Object.prototype.toString.call(n||null).replace(/\[object\s|\]/g,"").toLowerCase()===t.toLowerCase()}function t(n){return n.length}function r(n,r){for(var e=0;t(n)>e;e++)r.call(n,n[e],e)}function e(n){throw Error(n)}function u(t,e){function u(n){return Array.prototype.slice.call(n)}function i(t,e,i){return r(u(t),function(t){n(t,e)&&(i=t)}),i}function o(){return{key:i(arguments,"string","_"+(new Date).getTime()),fn:i(arguments,"function",function(){}),context:i(arguments,"object",t)}}function c(n){r(f[e],function(t,r){t.key===n&&f[e].splice(r,1)})}function s(n){return n?f:f[e]}function a(){return f.hasOwnProperty(e)||(f[e]=[]),f[e].push(o.apply(this,arguments)),this}function l(){var n=arguments;return f.hasOwnProperty(e)?(r(f[e],function(t){t.fn.apply(t.context,n)}),this):this}function p(n){return n?(c(n),this):(delete f[e],this)}function d(t,r){return t&&n(t,"function")&&t.call(this,s(r)),this}function h(){return{subscribe:a,sub:a,publish:l,pub:l,unsubscribe:p,unsub:p,list:d,prove:d}}return h()}function i(n){function t(n){e[n]=u(this,n)}var e={};return r(n,t.bind(this)),e}function o(t){function e(n,t){i[n][t]=u(this,t)}var i={};for(var o in t)n(t[o],"array")&&(i[o]={},r(t[o],e.bind(this,o)));return i}function c(t){return t||e("Jupiter requires a topic"),n(t,"array")?i(t):n(t,"object")?o(t):u(t)}var f={};return c});