/** * PublishSubscribe * A simple publish-subscribe implementation for PHP, Python, Node/XPCOM/JS * * @version: 1.1.0 * https://github.com/foo123/PublishSubscribe * **/ !function(t,s,n){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils.import?(t.$deps=t.$deps||{})&&(t.EXPORTED_SYMBOLS=[s])&&(t[s]=t.$deps[s]=n.call(t)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[s]=n.call(t)):"undefined"!=typeof System&&"function"==typeof System.register&&"function"==typeof System.import?System.register(s,[],function(e){e(s,n.call(t))}):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(s)?define(s,["module"],function(s){return n.moduleUri=s.uri,n.call(t)}):s in t||(t[s]=n.call(t)||1)&&"function"==typeof define&&define.amd&&define(function(){return t[s]})}("undefined"!=typeof self?self:this,"PublishSubscribe",function(t){"use strict";function s(t){if(t)for(var s in t)y.call(t,s)&&(this[s]=t[s])}function n(t,s,n,e,i){var o=this;o.target=t,o.topic=s?[].concat(s):[],n&&(o.originalTopic=[].concat(n)),o.tags=e?[].concat(e):[],o.namespaces=i?[].concat(i):[],o.data=null,o.timestamp=S(),o._propagates=!0,o._stopped=!1,o._aborted=!1}function e(t){return t.length>0}function i(t,s){var n,i,o,l;return s=String(s),n=s.indexOf(t[2]),i=s.indexOf(t[1]),-11){for(l=(1<=1;l--){for(c=[],p=0,a=1;p=t[i])return!1;return!0}function c(t,s,n,e,i,o){var l=!!n&&"tp_"+n,p=!!e&&"tg_"+e;if(l&&y.call(t.topics,l)){if(p&&y.call(t.topics[l].tags,p)){if(t.topics[l].tags[p].list.length&&(o<=0||a(t.topics[l].tags[p].namespaces,i,o)))return s.push([n,e,o>0,t.topics[l].tags[p]]),!0}else if(t.topics[l].notags.list.length&&(o<=0||a(t.topics[l].notags.namespaces,i,o)))return s.push([n,null,o>0,t.topics[l].notags]),!0}else if(p&&y.call(t.notopics.tags,p)){if(t.notopics.tags[p].list.length&&(o<=0||a(t.notopics.tags[p].namespaces,i,o)))return s.push([null,e,o>0,t.notopics.tags[p]]),!0}else if(t.notopics.notags.list.length&&(o<=0||a(t.notopics.notags.namespaces,i,o)))return s.push([null,null,!0,t.notopics.notags]),!0;return!1}function r(t,s,n){var e,i,l,p,a,r=o(t,n),u=r[1],f=r[2],g=r[3],h=r[0],b=[];if(p=f.length,a=g.length,e=u.length)for(;e;){if(i=u[0],y.call(s.topics,"tp_"+i))if(p>0)for(l=0;l0)for(l=0;l0)for(s=n-1;s>=0;s--)(i=e[s])[1]&&i[4]>0&&(e.splice(s,1),t.oneOffs=t.oneOffs>0?t.oneOffs-1:0);else t.oneOffs=0}return t}function f(t,s,e,i,o){if(e){var l,p,c,f,g,h,b,d,_,m,y,$,S,j,x=r(s,e,i);for(d=x[0],S=(y=x[2]).length,j=null,(c=(x=x[1]).length)>0&&((j=new n(t)).data=o,j.originalTopic=d?d.split(v):[]),l=0;l=p.subscribers.list.length&&(p.t+=1,p.start_topic=!0),i&&(p.hasNamespace?t.namespaces=e[3].slice(0):t.namespaces=[],e[4]=1,e[0](t))}else p.t+=1,p.start_topic=!0}t.non_local&&p.t>=p.topics.length&&(u(p.subscribers),"function"==typeof p.finish&&(l=p.finish,p.finish=null,l(t)),t&&(t.non_local.dispose(["t","s","start_topic","subscribers","topics","namespaces","hasNamespace","abort","finish"]),t.non_local=null,t.dispose(),t=null))}}}function h(t,s,e,i,o,l,p){if(e){var a,c=r(s,e,i),u=null;c[1].length>0&&((u=new n(t)).data=o,u.pipeline(a=g(u,c,l,p)),a(u))}}function b(t,s,n,e,o,p){if(s&&"function"==typeof e){var a,c,r,u,f,g,h,b=(n=i(t,n))[1].join(O),d=b.length,_=n[2],m=_.length;if(n=n[0].join(v),o=!0===o,p=!0===p,f={},m)for(h=0;h0)for(;--l>=0;)n===t.list[l][0]&&(i&&t.list[l][2]&&a(t.list[l][2],e,i)?(o=$(t.list[l][2]),p(t.namespaces,o,o.length),t.list[l][1]&&(t.oneOffs=t.oneOffs>0?t.oneOffs-1:0),t.list.splice(l,1)):i||(t.list[l][2]&&(o=$(t.list[l][2]),p(t.namespaces,o,o.length)),t.list[l][1]&&(t.oneOffs=t.oneOffs>0?t.oneOffs-1:0),t.list.splice(l,1)))}else if(!s&&i>0&&l>0)for(;--l>=0;)t.list[l][2]&&a(t.list[l][2],e,i)&&(o=$(t.list[l][2]),p(t.namespaces,o,o.length),t.list[l][1]&&(t.oneOffs=t.oneOffs>0?t.oneOffs-1:0),t.list.splice(l,1));else!s&&l>0&&(t.list=[],t.oneOffs=0,t.namespaces={})}function _(t,s,n,e){if(s){var o,l,p,a,c,r,u=(n=i(t,n))[1].join(O),f=n[2],g=u.length,h=f.length;if(n=n[0].join(v),c=n.length,p=!!c&&"tp_"+n,a=!!g&&"tg_"+u,(r=!(!e||"function"!=typeof e))||(e=null),c&&y.call(s.topics,p))g&&y.call(s.topics[p].tags,a)?(d(s.topics[p].tags[a],r,e,f,h),s.topics[p].tags[a].list.length||delete s.topics[p].tags[a]):g||d(s.topics[p].notags,r,e,f,h),s.topics[p].notags.list.length||$(s.topics[p].tags).length||delete s.topics[p];else if(!c&&(g||h))if(g){y.call(s.notopics.tags,a)&&(d(s.notopics.tags[a],r,e,f,h),s.notopics.tags[a].list.length||delete s.notopics.tags[a]);for(o in s.topics)y.call(s.topics,o)&&y.call(s.topics[o].tags,a)&&(d(s.topics[o].tags[a],r,e,f,h),s.topics[o].tags[a].list.length||delete s.topics[o].tags[a])}else{d(s.notopics.notags,r,e,f,h);for(l in s.notopics.tags)y.call(s.notopics.tags,l)&&(d(s.notopics.tags[l],r,e,f,h),s.notopics.tags[l].list.length||delete s.notopics.tags[l]);for(o in s.topics)if(y.call(s.topics,o)){d(s.topics[o].notags,r,e,f,h);for(l in s.topics[o].tags)y.call(s.topics[o].tags,l)&&(d(s.topics[o].tags[l],r,e,f,h),s.topics[o].tags[l].list.length||delete s.topics[o].tags[l])}}}}var m="prototype",y=Object[m].hasOwnProperty,v="/",O="#",$=Object.keys,S=Date.now?Date.now:function(){return(new Date).getTime()};s[m]={constructor:s,dispose:function(t){if(t)for(var s=0;s0&&t[0]&&(n._seps[0]=t[0]),s>1&&t[1]&&(n._seps[1]=t[1]),s>2&&t[2]&&(n._seps[2]=t[2])),n},trigger:function(t,s,n){var e=this;return 3>arguments.length&&(n=0),n=+n,2>arguments.length&&(s={}),n>0?setTimeout(function(){f(e,e._seps,e._pubsub$,t,s)},n):f(e,e._seps,e._pubsub$,t,s),e},pipeline:function(t,s,n,e,i){var o=this;return 5>arguments.length&&(i=0),i=+i,2>arguments.length&&(s={}),i>0?setTimeout(function(){h(o,o._seps,o._pubsub$,t,s,n||null,e||null)},i):h(o,o._seps,o._pubsub$,t,s,n||null,e||null),o},on:function(t,s){var n=this;return s&&"function"==typeof s&&b(n._seps,n._pubsub$,t,s),n},one:function(t,s){var n=this;return s&&"function"==typeof s&&b(n._seps,n._pubsub$,t,s,!0),n},on1:function(t,s){var n=this;return s&&"function"==typeof s&&b(n._seps,n._pubsub$,t,s,!1,!0),n},one1:function(t,s){var n=this;return s&&"function"==typeof s&&b(n._seps,n._pubsub$,t,s,!0,!0),n},off:function(t,s){var n=this;return _(n._seps,n._pubsub$,t,s||null),n}},j});