UNPKG

wqking-eventjs

Version:

eventjs is a JavaScript event library that provides tools that enable your application components to communicate with each other by dispatching events and listening for them. With eventpp you can easily implement signal/slot mechanism, or observer pattern

2 lines 4.92 kB
/*eventjs v0.0.1, by wqking, https://github.com/wqking/eventjs*/ if(void 0===eventjs)var eventjs={};"function"==typeof define&&define.amd?define(function(){return eventjs}):"object"==typeof module&&module.exports&&(module.exports=eventjs),function(t){"use strict";function s(t,e){this._d=null,this._c=null,this._p=t,this._f=e}function e(t){this._u=null,this._l=null,this._e=0,t=t||{},this._r=t.hasOwnProperty("canContinueInvoking")?t.canContinueInvoking:null,this._i=!!t.hasOwnProperty("argumentsAsArray")&&!!t.argumentsAsArray,this._i?(this.dispatch=this._s,this.applyDispatch=this._v):(this.dispatch=this._a,this.applyDispatch=this._j)}var n=e.prototype;n.append=function(t){var e=new s(t,this._b());return this._u?(e._d=this._l,this._l._c=e):this._u=e,this._l=e},n.prepend=function(t){var e=new s(t,this._b());return this._u?(e._c=this._u,this._u._d=e,this._u=e):(this._u=e,this._l=e),e},n.insert=function(t,e){var n=this._o(e);if(!n)return this.append(t);var i=new s(t,this._b());return i._d=n._d,(i._c=n)._d&&(n._d._c=i),n._d=i,n==this._u&&(this._u=i),i},n.remove=function(t){var e=this._o(t);return!!e&&(e._c&&(e._c._d=e._d),e._d&&(e._d._c=e._c),this._u==e&&(this._u=e._c),this._l==e&&(this._l=e._d),!(e._f=0))},n.empty=function(){return!this._u},n.has=function(t){return!!this._o(t)},n.hasAny=function(){return!!this._u},n._s=function(){for(var t=this._e,e=this._u;e&&!(0!=e._f&&t>=e._f&&(e._p.call(this,arguments),this._r&&!this._r.call(this,arguments)));)e=e._c},n._a=function(){for(var t=this._e,e=this._u;e&&!(0!=e._f&&t>=e._f&&(e._p.apply(this,arguments),this._r&&!this._r.apply(this,arguments)));)e=e._c},n._v=function(t){for(var e=this._e,n=this._u;n&&!(0!=n._f&&e>=n._f&&(n._p.call(this,t),this._r&&!this._r.call(this,t)));)n=n._c},n._j=function(t){for(var e=this._e,n=this._u;n&&!(0!=n._f&&e>=n._f&&(n._p.apply(this,t),this._r&&!this._r.apply(this,t)));)n=n._c},n.forEach=function(t){for(var e=this._u,n=this._e;e;)0!=e._f&&n>=e._f&&t(e._p),e=e._c},n.forEachIf=function(t){for(var e=this._u,n=this._e;e;){if(0!=e._f&&n>=e._f&&!t(e._p))return!1;e=e._c}return!0},n._o=function(t){for(var e=this._u;e;){if(e===t||e._p===t)return e;e=e._c}return null},n._b=function(){var t=++this._e;if(0==t){for(var e=this._u;e;)e._f=1,e=e._c;t=++this._e}return t},t.CallbackList=e}(eventjs),function(i){"use strict";function n(t,e){for(var n in e)t[n]=e[n];return t}function r(t){if(this._h={},t=t||{},this._g=t,this._m="function"==typeof t.getEvent?t.getEvent:null,this._n=t.hasOwnProperty("argumentPassingMode")?t.argumentPassingMode:r.defaultArgumentPassingMode,this._i=!!t.hasOwnProperty("argumentsAsArray")&&!!t.argumentsAsArray,this._x=t.mixins,this._w=this._x&&0<this._x.length,this._w)for(var e=0;e<this._x.length;++e)n(this,this._x[e])}r.argumentPassingIncludeEvent=1,r.argumentPassingExcludeEvent=2,r.defaultArgumentPassingMode=2;var t=r.prototype;t.appendListener=function(t,e){return this._q(t,!0).append(e)},t.prependListener=function(t,e){return this._q(t,!0).prepend(e)},t.insertListener=function(t,e,n){return this._q(t,!0).insert(e,n)},t.removeListener=function(t,e){var n=this._q(t,!1);return!!n&&n.remove(e)},t.hasListener=function(t,e){var n=this._q(t,!1);return!!n&&n.has(e)},t.hasAnyListener=function(t){var e=this._q(t,!1);return!!e&&e.hasAny()},t.dispatch=function(){this.applyDispatch(arguments)},t.applyDispatch=function(t){if(this._w)for(var e=0;e<this._x.length;++e){var n=this._x[e];if(n.mixinBeforeDispatch&&!n.mixinBeforeDispatch.call(this,t))return}if(this._m){if(this._i)var i=this._m.call(this,t);else i=this._m.apply(this,t);(s=this._q(i,!1))&&(this._n===r.argumentPassingIncludeEvent&&(t=[i].concat(t)),s.dispatch.apply(s,t))}else{var s;(s=this._q(t[0],!1))&&(this._n===r.argumentPassingExcludeEvent&&(t=Array.prototype.slice.call(t,1)),s.dispatch.apply(s,t))}},t.forEach=function(t,e){var n=this._q(t,!1);n&&n.forEach(t,e)},t.forEachIf=function(t,e){var n=this._q(t,!1);return!n||n.forEachIf(t,e)},t._q=function(t,e){if(this._h.hasOwnProperty(t))return this._h[t];if(e){var n=new i.CallbackList(this._g);return this._h[t]=n}return null},i.EventDispatcher=r}(eventjs),function(e){"use strict";function t(t){e.EventDispatcher.call(this,t),this._t=[]}var n=t.prototype=Object.create(e.EventDispatcher.prototype);n.enqueue=function(){this._t.push(arguments)},n.process=function(){var t=this._t;this._t=[];for(var e=t.length,n=0;n<e;++n)this.applyDispatch(t[n])},n.processOne=function(){0<this._t.length&&this.applyDispatch(this._t.shift())},n.processIf=function(t){var e=this._t;this._t=[];for(var n=[],i=e.length,s=0;s<i;++s){var r=e[s];if(this._i)var a=t.call(this,r);else a=t.apply(this,r);a?this.applyDispatch(r):n.push(r)}0<n.length&&(this._t=this._t.concat(n))},n.empty=function(){return 0===this._t.length},n.clearEvents=function(){this._t.length=0},n.peekEvent=function(){return this._t[0]},n.takeEvent=function(){return 0<this._t.length?this._t.shift():null},e.EventQueue=t}(eventjs);