evg_observable 2.15.3 → 2.15.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evg_observable",
3
- "version": "2.15.3",
3
+ "version": "2.15.4",
4
4
  "description": "Alternative fast and light library version - observable.",
5
5
  "main": "src/outLib/index.js",
6
6
  "types": "src/outLib/index.d.ts",
@@ -0,0 +1 @@
1
+ (()=>{"use strict";function s(s,e){return s.order>e.order?1:s.order<e.order?-1:0}function e(s,e){return s.order>e.order?-1:s.order<e.order?1:0}function r(s,e){const r=s.indexOf(e);return-1!==r&&(s[r]=s[s.length-1],s.length--,!0)}function t(s){return"next"in s?e=>s.next(e):s}class i{constructor(s){this.pipe=s,this.counter=s.chain.length?s.chain.length:0}case(s){this.counter++;const e=this.counter,r=this.pipe.chain;return r.push(t=>{t.isAvailable=!0,s(t.payload)&&(t.isBreak=!0),e!==r.length||t.isBreak||(t.isAvailable=!1)}),this}pushCases(s){if(!Array.isArray(s))return this;for(let e=0;e<s.length;e++)this.case(s[e]);return this}}class h{constructor(){this.chain=[],this.flow={isBreak:!1,isUnsubscribe:!1,isAvailable:!1,payload:null}}push(s){return this.chain.push(s),this}setOnce(){return this.push(s=>{this.listener(s.payload),s.isUnsubscribe=!0})}unsubscribeBy(s){return this.push(e=>{e.isAvailable=!0,s(e.payload)&&(e.isUnsubscribe=!0)})}refine(s){return this.push(e=>s(e.payload)&&(e.isAvailable=!0))}pushRefiners(s){if(!Array.isArray(s))return this;for(let e=0;e<s.length;e++)this.refine(s[e]);return this}switch(){return new n(this)}then(s){return this.push(e=>{e.payload=s(e.payload),e.isAvailable=!0})}serialize(){return this.push(s=>{s.payload=JSON.stringify(s.payload),s.isAvailable=!0})}deserialize(){return this.push(s=>{s.payload=JSON.parse(s.payload),s.isAvailable=!0})}processChain(s){const e=this.chain,r=this.flow,t=e.length;for(let s=0;s<t;s++){if(r.isUnsubscribe=!1,r.isAvailable=!1,e[s](r),r.isUnsubscribe)return this.unsubscribe();if(!r.isAvailable)return;if(r.isBreak)break}return s(r.payload)}}class n extends i{subscribe(s,e){return this.pipe.subscribe(s,e)}}class l extends h{constructor(s,e){super(),this.errorHandler=(s,e)=>{console.log(`(Unit of SubscribeObject).send(${s}) ERROR:`,e)},this._order=0,this.paused=!1,this.piped=!1,this.observer=s,this.piped=!!e}subscribe(s,e){return this.listener=function(s){if(Array.isArray(s)){const e=[];for(let r=0;r<s.length;r++)e.push(t(s[r]));return s=>{for(let r=0;r<e.length;r++)e[r](s)}}return t(s)}(s),e&&(this.errorHandler=e),this}unsubscribe(){this.observer&&(this.observer.unSubscribe(this),this.observer=null,this.listener=null,this.chain.length=0)}send(s){const e=this.listener;if(e){if(this.observer&&!this.paused)if(this.piped)try{this.flow.payload=s,this.flow.isBreak=!1,this.processChain(e)}catch(e){this.errorHandler(s,e)}else try{e(s)}catch(e){this.errorHandler(s,e)}}else this.unsubscribe()}resume(){this.paused=!1}pause(){this.paused=!0}get order(){return this._order}set order(s){this._order=s}}class u{constructor(){this.chain=[],this.flow={isBreak:!1,isAvailable:!1,payload:null},this.response={isOK:!1,payload:void 0}}get isEmpty(){return!this.chain.length}push(s){return this.chain.push(s),this}filter(s){return this.push(e=>s(e.payload)&&(e.isAvailable=!0))}pushFilters(s){if(!Array.isArray(s))return this;for(let e=0;e<s.length;e++)this.filter(s[e]);return this}switch(){return new a(this)}processChain(s){const e=this.chain,r=this.flow,t=this.response;t.isOK=!1,t.payload=void 0,r.payload=s,r.isBreak=!1;try{const s=e.length;for(let i=0;i<s;i++){if(r.isAvailable=!1,e[i](r),!r.isAvailable)return t;if(r.isBreak)break}}catch(s){return this.errHandler?this.errHandler(s,"Filter.processChain ERROR:"):console.log("Filter.processChain ERROR:",s),t}return t.isOK=!0,t.payload=r.payload,t}addErrorHandler(s){this.errHandler=s}}class a extends i{}class o{constructor(s){this.subs=[],this.enabled=!0,this.killed=!1,this.process=!1,this.trash=[],this.filters=new u,this._value=s}addFilter(s){return s&&this.filters.addErrorHandler(s),this.filters}disable(){this.enabled=!1}enable(){this.enabled=!0}get isEnable(){return this.enabled}next(s){if(this.killed)return;if(!this.enabled)return;if(!this.subs.length)return;if(!this.filters.isEmpty&&!this.filters.processChain(s).isOK)return;this.process=!0,this._value=s;const e=this.subs,r=e.length;for(let t=0;t<r;t++)e[t].send(s);this.process=!1,this.trash.length&&this.clearTrash()}stream(s){if(!this.killed&&this.enabled)for(let e=0;e<s.length;e++)this.next(s[e])}clearTrash(){const s=this.trash.length;for(let e=0;e<s;e++)this.unSubscribe(this.trash[e]);this.trash.length=0}unSubscribe(s){this.killed||(this.process&&s?this.trash.push(s):this.subs&&r(this.subs,s))}destroy(){if(!this.killed){if(this.killed=!0,!this.process)return this._value=null,void(this.subs.length=0);Promise.resolve().then(()=>{this._value=null,this.subs.length=0})}}unsubscribeAll(){if(!this.killed){if(this.process){const s=this.subs;for(let e=0;e<s.length;e++)this.trash.push(s[e]);return}this.subs.length=0}}getValue(){if(!this.killed)return this._value}size(){return this.killed?0:this.subs.length}subscribe(s,e){if(this.killed)return;if(!this.isListener(s))return;const r=new l(this,!1);return this.addObserver(r,s,e),r}addObserver(s,e,r){s.subscribe(e,r),this.subs.push(s)}isListener(s){return!this.killed&&!!s}pipe(){if(this.killed)return;const s=new l(this,!0);return this.subs.push(s),s}get isDestroyed(){return this.killed}}class c extends l{constructor(s,e){super(s,e)}get order(){return this._order}set order(s){!this.observer||this.observer&&this.observer.isDestroyed?this._order=void 0:(this._order=s,this.observer.sortByOrder())}subscribe(s,e){return super.subscribe(s,e),this}setOnce(){return super.setOnce()}}const d=window;d.Observable=o,d.Collector=class{constructor(){this.arr=[],this.killed=!1}collect(...s){this.killed||this.arr.push(...s)}unsubscribe(s){this.killed||(s?.unsubscribe(),r(this.arr,s))}unsubscribeAll(){if(this.killed)return;const s=this.arr;for(let e=0;e<s.length;e++)s[e].unsubscribe();s.length=0}size(){return this.killed?0:this.arr.length}destroy(){this.unsubscribeAll(),this.arr.length=0,this.arr=0,this.killed=!0}get isDestroyed(){return this.killed}},d.OrderedObservable=class extends o{constructor(){super(...arguments),this.sortDirection=s}setAscendingSort(){return this.sortDirection=s,this.sortByOrder()}setDescendingSort(){return this.sortDirection=e,this.sortByOrder()}sortByOrder(){return!this.killed&&(this.subs.sort(this.sortDirection),!0)}subscribe(s,e){if(!this.isListener(s))return;const r=new c(this,!1);return this.addObserver(r,s,e),r}pipe(){if(this.killed)return;const s=new c(this,!0);return this.subs.push(s),s}unSubscribe(s){this.killed||(this.process&&s?this.trash.push(s):this.subs&&r(this.subs,s))}}})();