PHP Classes

File: src/js/PublishSubscribe.min.js

Recommend this page to a friend!
  Classes of Nikos M.  >  PHP Publish Subscribe  >  src/js/PublishSubscribe.min.js  >  Download  
File: src/js/PublishSubscribe.min.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: PHP Publish Subscribe
Register and call handlers of events by name
Author: By
Last change:
Date: 2 years ago
Size: 10,854 bytes
 

Contents

Class file image Download
/** * 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]),-1<n?(l=s.slice(n).split(t[2]).filter(e).sort(),s=s.slice(0,n)):l=[],-1<i?(o=s.slice(i).split(t[1]).filter(e).sort(),s=s.slice(0,i)):o=[],s=s.split(t[0]).filter(e),[s,o,l]}function o(t,s){var n,e,o,l,p,a,c,r=[],u=[];for(n=(s=i(t,s))[2],e=s[1],o=(s=s[0]).length;o;)r.push(s.join(v)),s.pop(),o--;if((o=e.length)>1){for(l=(1<<o)-1;l>=1;l--){for(c=[],p=0,a=1;p<o;p++,a=1<<p)l!==a&&l&a&&c.push(e[p]);c.length&&u.push(c.join(O))}u=u.concat(e)}else o&&u.push(e[0]);return[r.length?r[0]:"",r,u,n]}function l(t,s,n){var e,i;for(e=0;e<n;e++)i="ns_"+s[e],y.call(t,i)?t[i]++:t[i]=1}function p(t,s,n){var e,i;for(e=0;e<n;e++)i="ns_"+s[e],y.call(t,i)&&(t[i]--,t[i]<=0&&delete t[i])}function a(t,s,n){var e,i;for(e=0;e<n;e++)if(i="ns_"+s[e],!y.call(t,i)||0>=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;l<p;l++)c(s,b,i,f[l],g,a);else c(s,b,i,null,g,a);u.shift(),e--}if(p>0)for(l=0;l<p;l++)c(s,b,null,f[l],g,a);return c(s,b,null,null,g,a),[h,b,g]}function u(t){if(t&&y.call(t,"list")){var s,n,e,i;if((e=t.list)&&(n=e.length))if(t.oneOffs>0)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<c;l++){for(_=x[l][0],m=x[l][1],j.topic=_?_.split(v):[],j.tags=m?m.split(O):[],$=x[l][2],g=[],f=(h=x[l][3]).list.length,p=0;p<f;p++)(b=h.list[p])[1]&&b[4]||!(!$||b[2]&&a(b[2],y,S))||g.push(b);for(f=g.length,p=0;p<f&&(b=g[p],j.namespaces=$?b[3].slice(0):[],b[4]=1,!1!==b[0](j)&&!j.stopped()&&!j.aborted());p++);if(u(h),j.aborted()||!j.propagates())break}j&&(j.dispose(),j=null)}}function g(t,n,e,i){var o=n[0],l=n[2],n=n[1];t.non_local=new s({t:0,s:0,start_topic:!0,subscribers:null,topics:n,namespaces:l,hasNamespace:!1,abort:e,finish:i}),t.originalTopic=o?o.split(v):[];return function(t){if(t.non_local){var s,n,e,i,o,l,p=t.non_local;if(p.t<p.topics.length){if(p.start_topic){if(u(p.subscribers),t.aborted()||!t.propagates())return t.aborted()&&"function"==typeof p.abort&&(o=p.abort,p.abort=null,o(t),"function"==typeof p.finish&&(l=p.finish,p.finish=null,l(t))),!1;s=p.topics[p.t][0],n=p.topics[p.t][1],t.topic=s?s.split(v):[],t.tags=n?n.split(O):[],p.hasNamespace=p.topics[p.t][2],p.subscribers=p.topics[p.t][3],p.s=0,p.start_topic=!1}if(p.s<p.subscribers.list.length){if(t.aborted()||t.stopped())return u(p.subscribers),t.aborted()&&"function"==typeof p.abort&&(o=p.abort,p.abort=null,o(t),"function"==typeof p.finish&&(l=p.finish,p.finish=null,l(t))),!1;for(i=!1;p.s<p.subscribers.list.length&&!i;)(e=p.subscribers.list[p.s])[1]&&e[4]||!(!p.hasNamespace||e[2]&&a(e[2],p.namespaces,p.namespaces.length))||(i=!0),p.s+=1;p.s>=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;h<m;h++)f["ns_"+_[h]]=1;g=_.slice(0),c=null,n.length?(r="tp_"+n,y.call(s.topics,r)||(s.topics[r]={notags:{namespaces:{},list:[],oneOffs:0},tags:{}}),d?(u="tg_"+b,y.call(s.topics[r].tags,u)||(s.topics[r].tags[u]={namespaces:{},list:[],oneOffs:0}),c=s.topics[r].tags[u]):c=s.topics[r].notags):d?(u="tg_"+b,y.call(s.notopics.tags,u)||(s.notopics.tags[u]={namespaces:{},list:[],oneOffs:0}),c=s.notopics.tags[u]):m&&(c=s.notopics.notags),null!==c&&(a=m?[e,o,f,g,0]:[e,o,!1,[],0],p?c.list.unshift(a):c.list.push(a),o&&c.oneOffs++,m&&l(c.namespaces,_,m))}}function d(t,s,n,e,i){var o,l=t.list.length;if(s){if(null!=n&&l>0)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;s<t.length;s++)this[t[s]]=null;return this}},n[m]={constructor:n,target:null,topic:null,originalTopic:null,tags:null,namespaces:null,data:null,timestamp:0,is_pipelined:!1,_next:null,_propagates:!0,_stopped:!1,_aborted:!1,dispose:function(){var t=this;return t.target=null,t.topic=null,t.originalTopic=null,t.tags=null,t.namespaces=null,t.data instanceof s&&t.data.dispose(),t.data=null,t.timestamp=null,t.is_pipelined=!1,t._propagates=!0,t._stopped=!0,t._aborted=!1,t._next=null,t},next:function(){return"function"==typeof this._next&&this._next(this),this},pipeline:function(t){return arguments.length||(t=null),"function"==typeof t?(this._next=t,this.is_pipelined=!0):(this._next=null,this.is_pipelined=!1),this},propagate:function(t){return arguments.length||(t=!0),this._propagates=!!t,this},stop:function(t){return arguments.length||(t=!0),this._stopped=!!t,this},abort:function(t){return arguments.length||(t=!0),this._aborted=!!t,this},aborted:function(){return this._aborted},propagates:function(){return this._propagates},stopped:function(){return this._stopped}};var j=function(){if(!(this instanceof j))return new j;this.initPubSub()};return j.VERSION="1.1.0",j.Event=n,j.Data=function(t){return new s(t)},j[m]={constructor:j,_seps:null,_pubsub$:null,initPubSub:function(){var t=this;return t._seps=["/","#","@"],t._pubsub$={notopics:{notags:{namespaces:{},list:[],oneOffs:0},tags:{}},topics:{}},t},disposePubSub:function(){var t=this;return t._seps=null,t._pubsub$=null,t},setSeparators:function(t){var s,n=this;return t&&(s=t.length)&&(s>0&&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});