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 5.25 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._a=null,this._w=null,this._y=t,this._o=e}function e(t){this._q=null,this._u=null,this._f=0,t=t||{},this._d=t.hasOwnProperty("canContinueInvoking")?t.canContinueInvoking:null,this._j=!!t.hasOwnProperty("argumentsAsArray")&&!!t.argumentsAsArray,this._j?(this.dispatch=this._s,this.applyDispatch=this._n):(this.dispatch=this._k,this.applyDispatch=this._p)}var n=e.prototype;n.append=function(t){var e=new s(t,this._h());return this._q?(e._a=this._u,this._u._w=e):this._q=e,this._u=e},n.prepend=function(t){var e=new s(t,this._h());return this._q?(e._w=this._q,this._q._a=e,this._q=e):(this._q=e,this._u=e),e},n.insert=function(t,e){var n=this._x(e);if(!n)return this.append(t);var i=new s(t,this._h());return i._a=n._a,(i._w=n)._a&&(n._a._w=i),n._a=i,n==this._q&&(this._q=i),i},n.remove=function(t){var e=this._x(t);return!!e&&(e._w&&(e._w._a=e._a),e._a&&(e._a._w=e._w),this._q==e&&(this._q=e._w),this._u==e&&(this._u=e._a),!(e._o=0))},n.empty=function(){return!this._q},n.has=function(t){return!!this._x(t)},n.hasAny=function(){return!!this._q},n._s=function(){for(var t=this._f,e=this._q;e&&!(0!=e._o&&t>=e._o&&(e._y.call(this,arguments),this._d&&!this._d.call(this,arguments)));)e=e._w},n._k=function(){for(var t=this._f,e=this._q;e&&!(0!=e._o&&t>=e._o&&(e._y.apply(this,arguments),this._d&&!this._d.apply(this,arguments)));)e=e._w},n._n=function(t){for(var e=this._f,n=this._q;n&&!(0!=n._o&&e>=n._o&&(n._y.call(this,t),this._d&&!this._d.call(this,t)));)n=n._w},n._p=function(t){for(var e=this._f,n=this._q;n&&!(0!=n._o&&e>=n._o&&(n._y.apply(this,t),this._d&&!this._d.apply(this,t)));)n=n._w},n.forEach=function(t){for(var e=this._q,n=this._f;e;)0!=e._o&&n>=e._o&&t(e._y),e=e._w},n.forEachIf=function(t){for(var e=this._q,n=this._f;e;){if(0!=e._o&&n>=e._o&&!t(e._y))return!1;e=e._w}return!0},n._x=function(t){for(var e=this._q;e;){if(e===t||e._y===t)return e;e=e._w}return null},n._h=function(){var t=++this._f;if(0==t){for(var e=this._q;e;)e._o=1,e=e._w;t=++this._f}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._c={},t=t||{},this._g=t,this._i="function"==typeof t.getEvent?t.getEvent:null,this._l=t.hasOwnProperty("argumentPassingMode")?t.argumentPassingMode:r.defaultArgumentPassingMode,this._j=!!t.hasOwnProperty("argumentsAsArray")&&!!t.argumentsAsArray,this._t=t.mixins,this._b=this._t&&0<this._t.length,this._b)for(var e=0;e<this._t.length;++e)n(this,this._t[e])}r.argumentPassingIncludeEvent=1,r.argumentPassingExcludeEvent=2,r.defaultArgumentPassingMode=2;var t=r.prototype;t.appendListener=function(t,e){return this._e(t,!0).append(e)},t.prependListener=function(t,e){return this._e(t,!0).prepend(e)},t.insertListener=function(t,e,n){return this._e(t,!0).insert(e,n)},t.removeListener=function(t,e){var n=this._e(t,!1);return!!n&&n.remove(e)},t.hasListener=function(t,e){var n=this._e(t,!1);return!!n&&n.has(e)},t.hasAnyListener=function(t){var e=this._e(t,!1);return!!e&&e.hasAny()},t.dispatch=function(){this.applyDispatch(arguments)},t.applyDispatch=function(t){if(this._b)for(var e=0;e<this._t.length;++e){var n=this._t[e];if(n.mixinBeforeDispatch&&!n.mixinBeforeDispatch.call(this,t))return}if(this._i){if(this._j)var i=this._i.call(this,t);else i=this._i.apply(this,t);(s=this._e(i,!1))&&(this._l===r.argumentPassingIncludeEvent&&(t=[i].concat(t)),s.dispatch.apply(s,t))}else{var s;(s=this._e(t[0],!1))&&(this._l===r.argumentPassingExcludeEvent&&(t=Array.prototype.slice.call(t,1)),s.dispatch.apply(s,t))}},t.forEach=function(t,e){var n=this._e(t,!1);n&&n.forEach(t,e)},t.forEachIf=function(t,e){var n=this._e(t,!1);return!n||n.forEachIf(t,e)},t._e=function(t,e){if(this._c.hasOwnProperty(t))return this._c[t];if(e){var n=new i.CallbackList(this._g);return this._c[t]=n}return null},i.EventDispatcher=r}(eventjs),function(e){"use strict";function t(t){e.EventDispatcher.call(this,t),this._r=[]}var n=t.prototype=Object.create(e.EventDispatcher.prototype);n.enqueue=function(){this._r.push(arguments)},n.process=function(){var t=this._r;this._r=[];for(var e=t.length,n=0;n<e;++n)this.applyDispatch(t[n])},n.processOne=function(){0<this._r.length&&this.applyDispatch(this._r.shift())},n.processIf=function(t){var e=this._r;this._r=[];for(var n=[],i=e.length,s=0;s<i;++s){var r=e[s];if(this._j)var a=t.call(this,r);else a=t.apply(this,r);a?this.applyDispatch(r):n.push(r)}0<n.length&&(this._r=this._r.concat(n))},n.empty=function(){return 0===this._r.length},n.clearEvents=function(){this._r.length=0},n.peekEvent=function(){return this._r[0]},n.takeEvent=function(){return 0<this._r.length?this._r.shift():null},e.EventQueue=t}(eventjs),function(t){"use strict";var e=t;function n(t){this._v=new e.CallbackList(t)}var i=n.prototype;i.appendFilter=function(t){this._v.append(t)},i.removeFilter=function(t){this._v.remove(t)},i.mixinBeforeDispatch=function(e){return!(!this._v.empty()&&!this._v.forEachIf(function(t){return t.call(t,e)}))},t.MixinFilter=n}(eventjs);