mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-03 05:22:26 +08:00
e7180a86ce
This also allowed to remove all webpack 'externals' overhead.
7 lines
2.1 KiB
JavaScript
7 lines
2.1 KiB
JavaScript
/*
|
|
JS Signals <http://millermedeiros.github.com/js-signals/>
|
|
Released under the MIT license
|
|
Author: Miller Medeiros
|
|
Version: 1.0.0 - Build: 268 (2012/11/29 05:48 PM)
|
|
*/
|
|
(i=>{class t{constructor(i,t,e,s,n){this.active=!0,this.params=null,this._listener=t,this._isOnce=e,this.context=s,this._signal=i,this._priority=n||0}execute(i){var t,e;return this.active&&this._listener&&(e=this.params?this.params.concat(i):i,t=this._listener.apply(this.context,e),this._isOnce&&this.detach()),t}detach(){return this.isBound()?this._signal.remove(this._listener,this.context):null}isBound(){return!!this._signal&&!!this._listener}isOnce(){return this._isOnce}getListener(){return this._listener}getSignal(){return this._signal}_destroy(){delete this._signal,delete this._listener,delete this.context}}function e(i,t){if("function"!=typeof i)throw new Error("listener is a required param of {fn}() and should be a Function.".replace("{fn}",t))}class s{constructor(){this.memorize=!1,this.active=!0,this._bindings=[],this._prevParams=null;var i=this;this.dispatch=((...t)=>s.prototype.dispatch.apply(i,t))}_indexOfListener(i,t){for(var e,s=this._bindings.length;s--;)if((e=this._bindings[s])._listener===i&&e.context===t)return s;return-1}add(i,s,n){e(i,"add");var r,h=this._indexOfListener(i,s);if(-1!==h){if(!1!==(r=this._bindings[h]).isOnce())throw new Error("You cannot addOnce() then add() the same listener without removing the relationship first.")}else{r=new t(this,i,!1,s,n);var a=this._bindings.length;do{--a}while(this._bindings[a]&&r._priority<=this._bindings[a]._priority);this._bindings.splice(a+1,0,r)}return this.memorize&&this._prevParams&&r.execute(this._prevParams),r}remove(i,t){e(i,"remove");var s=this._indexOfListener(i,t);return-1!==s&&(this._bindings[s]._destroy(),this._bindings.splice(s,1)),i}removeAll(){for(var i=this._bindings.length;i--;)this._bindings[i]._destroy();this._bindings.length=0}dispatch(...i){if(this.active){var t,e=this._bindings.length;if(this.memorize&&(this._prevParams=i),e){t=this._bindings.slice();do{e--}while(t[e]&&!1!==t[e].execute(i))}}}dispose(){this.removeAll(),delete this._bindings,delete this._prevParams}}var n=s;n.Signal=s,i.signals=n})(this);
|