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