evg_observable 1.14.55 → 2.14.56

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/README.md CHANGED
@@ -216,46 +216,6 @@ observable$.next({message: "some message3", isNeedUnsubscribe: true});
216
216
 
217
217
  Observable will send a value to the listener only if condition returns "true". There is no automatic unsubscription.
218
218
 
219
- ### pipe().emitMatch(condition)
220
-
221
- Observable will send a value to the subscriber only if the return value of the condition matches the data being sent. In
222
- this case, there is no automatic unsubscription.
223
-
224
- ```ts
225
- import {Observable} from "evg_observable";
226
-
227
- const observable$ = new Observable('Some typed data (not only string)');
228
- const listener1 = (value: string) => console.log('listener1:', value);
229
- const listener2 = (value: string) => console.log('listener2:', value);
230
- const TARGET_DATA = 'TARGET_DATA';
231
-
232
- const subscriber1 = observable$
233
- .pipe()
234
- .emitMatch(() => TARGET_DATA)
235
- .subscribe(listener1);
236
- const subscriber2 = observable$.subscribe(listener2);
237
-
238
- console.log(observable$.getValue());
239
- // Print to console - Some typed data (not only string)
240
-
241
- observable$.next('Next1 typed data');
242
- // Print to console - listener2: Next1 typed data
243
-
244
- observable$.next('Next2 typed data');
245
- // Print to console - listener2: Next2 typed data
246
-
247
- observable$.next(TARGET_DATA);
248
- // Print to console - listener1: TARGET_DATA
249
- // Print to console - listener2: TARGET_DATA
250
-
251
- observable$.next('Next4 typed data');
252
- // Print to console - listener2: Next4 typed data
253
-
254
- observable$.next(TARGET_DATA);
255
- // Print to console - listener1: TARGET_DATA
256
- // Print to console - listener2: TARGET_DATA
257
- ```
258
-
259
219
  ### pipe().serialize()
260
220
 
261
221
  To convert the observable's data to JSON format, you can use the serialize method. This method turns the observer's
@@ -501,8 +461,8 @@ women$.pipe()
501
461
 
502
462
  // Stream the list of people by applying the age filters
503
463
  personal$.pipe()
504
- .emitByPositive(youngAgeFilter)
505
- .emitByPositive(oldAgeFilter)
464
+ .refine(youngAgeFilter)
465
+ .refine(oldAgeFilter)
506
466
  .subscribe([men$, women$]);
507
467
 
508
468
  // Stream the list of people considering the hair color
@@ -614,14 +574,9 @@ observable is set to be a once-off observable to which a listener is subscribed.
614
574
  | method | will return | description |
615
575
  |:-------------------------------------|:---------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
616
576
  | `.setOnce()` | pipe object | observable will send a value to the subscriber only once, and the subscriber will unsubscribe. |
617
- | `.unsubscribeByNegative(*condition)` | pipe object | observable will send a value to the subscriber as long as the condition is positive, on the first negative result, the subscriber will unsubscribe |
618
- | `.unsubscribeByPositive(*condition)` | pipe object | observable will send a value to the subscriber as long as the condition is negative, on the first positive result, the subscriber will unsubscribe |
619
577
  | `.unsubscribeBy(*condition)` | pipe object | observable will send a value to the subscriber as long as the condition is negative, on the first positive result, the subscriber will unsubscribe |
620
- | `.emitByNegative(*condition)` | pipe object | observable will send a value to the listener only if condition returns "false", there is no automatic unsubscription |
621
- | `.emitByPositive(*condition)` | pipe object | observable will send a value to the listener only if condition returns "true", there is no automatic unsubscription |
622
578
  | `.refine(*condition)` | pipe object | observable will send a value to the listener only if condition returns "true", there is no automatic unsubscription |
623
579
  | `.pushRefiners(*conditions)` | pipe object | This method allows you to add a group of conditions for filtering data in the pipeline chain. |
624
- | `.emitMatch(*condition)` | pipe object | observable will send a value to the subscriber only if the return value of the condition matches the data being sent, in this case, there is no automatic unsubscription |
625
580
  | `.switch()` | SwitchCase object | transitions the pipe into switch-case mode. In this mode, only the first condition that returns a positive result is triggered, and all others are ignored. This allows you to handle multiple cases more conveniently. |
626
581
  | `.case(*condition)` | PipeCase object | Adds a condition to the chain of cases. The entire chain operates on the principle of "OR". This is different from other pipe methods which, when chained, operate on the principle of "AND". |
627
582
  | `.pushCases(*conditions)` | PipeCase object | This method allows you to add a group of conditions for filtering cases data in the pipeline chain. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evg_observable",
3
- "version": "1.14.55",
3
+ "version": "2.14.56",
4
4
  "description": "Alternative fast and light library version - observable.",
5
5
  "main": "src/outLib/index.js",
6
6
  "directories": {
@@ -1 +1 @@
1
- (()=>{"use strict";const s=(s,e)=>s.order>e.order?1:s.order<e.order?-1:0,e=(s,e)=>s.order>e.order?-1:s.order<e.order?1:0;function i(s,e){const i=s.indexOf(e);return-1!==i&&(s[i]=s[s.length-1],s.length=s.length-1,!0)}function t(s){return"next"in s?e=>s.next(e):s}class r{constructor(){this.chainHandlers=[],this.pipeData={isBreakChain:!1,isNeedUnsubscribe:!1,isAvailable:!1,payload:null}}setOnce(){const s=this.pipeData;return this.chainHandlers.push((()=>{this.listener(s.payload),s.isNeedUnsubscribe=!0})),this}unsubscribeByNegative(s){const e=this.pipeData;return this.chainHandlers.push((()=>{e.isAvailable=!0,s(e.payload)||(e.isNeedUnsubscribe=!0)})),this}unsubscribeByPositive(s){const e=this.pipeData;return this.chainHandlers.push((()=>{e.isAvailable=!0,s(e.payload)&&(e.isNeedUnsubscribe=!0)})),this}unsubscribeBy(s){return this.unsubscribeByPositive(s)}emitByNegative(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)||(e.isAvailable=!0)})),this}emitByPositive(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)&&(e.isAvailable=!0)})),this}refine(s){return this.emitByPositive(s)}pushRefiners(s){if(!Array.isArray(s))return this;for(let e=0;e<s.length;e++)this.emitByPositive(s[e]);return this}emitMatch(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)==e.payload&&(e.isAvailable=!0)})),this}switch(){return new n(this)}then(s){const e=this.pipeData;return this.chainHandlers.push((()=>{e.payload=s(e.payload),e.isAvailable=!0})),this}serialize(){const s=this.pipeData;return this.chainHandlers.push((()=>{s.payload=JSON.stringify(s.payload),s.isAvailable=!0})),this}deserialize(){const s=this.pipeData;return this.chainHandlers.push((()=>{s.payload=JSON.parse(s.payload),s.isAvailable=!0})),this}processChain(s){const e=this.chainHandlers,i=this.pipeData;for(let s=0;s<e.length;s++){if(i.isNeedUnsubscribe=!1,i.isAvailable=!1,e[s](),i.isNeedUnsubscribe)return this.unsubscribe();if(!i.isAvailable)return;if(i.isBreakChain)break}return s(i.payload)}}class n{constructor(s){this.pipe=s,this.caseCounter=s.chainHandlers.length?s.chainHandlers.length:0}subscribe(s,e){return this.pipe.subscribe(s,e)}case(s){this.caseCounter++;const e=this.caseCounter,i=this.pipe.pipeData,t=this.pipe.chainHandlers;return t.push((()=>{i.isAvailable=!0,s(i.payload)&&(i.isBreakChain=!0),e!==t.length||i.isBreakChain||(i.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 extends r{constructor(s,e){super(),this.errorHandler=(s,e)=>{console.log(`(Unit of SubscribeObject).send(${s}) ERROR:`,e)},this._order=0,this.isPaused=!1,this.isPipe=!1,this.observable=s,this.isPipe=!!e}subscribe(s,e){return this.listener=function(s){if(Array.isArray(s)){const e=[];for(let i=0;i<s.length;i++)e.push(t(s[i]));return s=>{for(let i=0;i<e.length;i++)e[i](s)}}return t(s)}(s),e&&(this.errorHandler=e),this}unsubscribe(){this.observable&&(this.observable.unSubscribe(this),this.observable=null,this.listener=null,this.chainHandlers.length=0)}send(s){try{this.pipeData.payload=s,this.pipeData.isBreakChain=!1,this.processValue(s)}catch(e){this.errorHandler(s,e)}}resume(){this.isPaused=!1}pause(){this.isPaused=!0}get order(){return this._order}set order(s){this._order=s}processValue(s){const e=this.listener;return e&&this.observable?this.isPaused?void 0:this.isPipe?this.processChain(e):e(s):this.unsubscribe()}}class a{constructor(){this.chainHandlers=[],this.pipeData={isBreakChain:!1,isAvailable:!1,payload:null},this.response={isOK:!1,payload:void 0}}get isEmpty(){return!this.chainHandlers.length}filter(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)&&(e.isAvailable=!0)})),this}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 l(this)}processChain(s){const e=this.chainHandlers,i=this.pipeData,t=this.response;t.isOK=!1,t.payload=void 0,i.payload=s,i.isBreakChain=!1;try{for(let s=0;s<e.length;s++){if(i.isAvailable=!1,e[s](),!i.isAvailable)return t;if(i.isBreakChain)break}}catch(s){return this.errorHandler?this.errorHandler(s,"Filter.processChain ERROR:"):console.log("Filter.processChain ERROR:",s),t}return t.isOK=!0,t.payload=i.payload,t}addErrorHandler(s){this.errorHandler=s}}class l{constructor(s){this.pipe=s,this.caseCounter=s.chainHandlers.length?s.chainHandlers.length:0}case(s){this.caseCounter++;const e=this.caseCounter,i=this.pipe.pipeData,t=this.pipe.chainHandlers;return t.push((()=>{i.isAvailable=!0,s(i.payload)&&(i.isBreakChain=!0),e!==t.length||i.isBreakChain||(i.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 o{constructor(s){this.value=s,this.listeners=[],this._isEnable=!0,this._isDestroyed=!1,this.isNextProcess=!1,this.listenersForUnsubscribe=[],this.filterCase=new a}addFilter(s){return s&&this.filterCase.addErrorHandler(s),this.filterCase}disable(){this._isEnable=!1}enable(){this._isEnable=!0}get isEnable(){return this._isEnable}next(s){if(!this._isDestroyed&&this._isEnable&&(this.filterCase.isEmpty||this.filterCase.processChain(s).isOK)){this.isNextProcess=!0,this.value=s;for(let e=0;e<this.listeners.length;e++)this.listeners[e].send(s);this.isNextProcess=!1,this.listenersForUnsubscribe.length&&this.handleListenersForUnsubscribe()}}stream(s){if(!this._isDestroyed&&this._isEnable)for(let e=0;e<s.length;e++)this.next(s[e])}handleListenersForUnsubscribe(){const s=this.listenersForUnsubscribe.length;for(let e=0;e<s;e++)this.unSubscribe(this.listenersForUnsubscribe[e]);this.listenersForUnsubscribe.length=0}unSubscribe(s){this._isDestroyed||(this.isNextProcess&&s?this.listenersForUnsubscribe.push(s):this.listeners&&i(this.listeners,s))}destroy(){this.value=null,this.unsubscribeAll(),this.listeners=null,this._isDestroyed=!0}unsubscribeAll(){this._isDestroyed||(this.listeners.length=0)}getValue(){if(!this._isDestroyed)return this.value}size(){return this._isDestroyed?0:this.listeners.length}subscribe(s,e){if(!this.isSubsValid(s))return;const i=new h(this,!1);return this.addObserver(i,s,e),i}addObserver(s,e,i){s.subscribe(e,i),this.listeners.push(s)}isSubsValid(s){return!this._isDestroyed&&!!s}pipe(){if(this._isDestroyed)return;const s=new h(this,!0);return this.listeners.push(s),s}get isDestroyed(){return this._isDestroyed}}class u extends h{constructor(s,e){super(s,e)}get order(){return this._order}set order(s){!this.observable||this.observable&&this.observable.isDestroyed?this._order=void 0:(this._order=s,this.observable.sortByOrder())}subscribe(s,e){return super.subscribe(s,e),this}setOnce(){return super.setOnce()}unsubscribeByNegative(s){return super.unsubscribeByNegative(s)}unsubscribeByPositive(s){return super.unsubscribeByPositive(s)}emitByNegative(s){return super.emitByNegative(s)}emitByPositive(s){return super.emitByPositive(s)}emitMatch(s){return super.emitMatch(s)}}const c=window;c.Observable=o,c.Collector=class{constructor(){this.list=[],this._isDestroyed=!1}collect(...s){this._isDestroyed||this.list.push(...s)}unsubscribe(s){this._isDestroyed||(s?.unsubscribe(),i(this.list,s))}unsubscribeAll(){if(!this._isDestroyed)for(;this.list.length>0;)this.unsubscribe(this.list.pop())}size(){return this._isDestroyed?0:this.list.length}destroy(){this.unsubscribeAll(),this.list.length=0,this.list=0,this._isDestroyed=!0}get isDestroyed(){return this._isDestroyed}},c.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._isDestroyed&&(this.listeners.sort(this.sortDirection),!0)}subscribe(s,e){if(!this.isSubsValid(s))return;const i=new u(this,!1);return this.addObserver(i,s,e),i}pipe(){if(this._isDestroyed)return;const s=new u(this,!0);return this.listeners.push(s),s}unSubscribe(s){this._isDestroyed||(this.isNextProcess&&s?this.listenersForUnsubscribe.push(s):this.listeners&&function(s,e){const i=s.indexOf(e);-1!==i&&s.splice(i,1)}(this.listeners,s))}}})();
1
+ (()=>{"use strict";const s=(s,i)=>s.order>i.order?1:s.order<i.order?-1:0,i=(s,i)=>s.order>i.order?-1:s.order<i.order?1:0;function e(s,i){const e=s.indexOf(i);return-1!==e&&(s[e]=s[s.length-1],s.length=s.length-1,!0)}function t(s){return"next"in s?i=>s.next(i):s}class r{constructor(s){this.pipe=s,this.counter=s.chain.length?s.chain.length:0}case(s){this.counter++;const i=this.counter,e=this.pipe.chain;return e.push((t=>{t.isAvailable=!0,s(t.payload)&&(t.isBreak=!0),i!==e.length||t.isBreak||(t.isAvailable=!1)})),this}pushCases(s){if(!Array.isArray(s))return this;for(let i=0;i<s.length;i++)this.case(s[i]);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((i=>{i.isAvailable=!0,s(i.payload)&&(i.isUnsubscribe=!0)}))}refine(s){return this.push((i=>{s(i.payload)&&(i.isAvailable=!0)}))}pushRefiners(s){if(!Array.isArray(s))return this;for(let i=0;i<s.length;i++)this.refine(s[i]);return this}switch(){return new l(this)}then(s){return this.push((i=>{i.payload=s(i.payload),i.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 i=this.chain,e=this.flow;for(let s=0;s<i.length;s++){if(e.isUnsubscribe=!1,e.isAvailable=!1,i[s](e),e.isUnsubscribe)return this.unsubscribe();if(!e.isAvailable)return;if(e.isBreak)break}return s(e.payload)}}class l extends r{subscribe(s,i){return this.pipe.subscribe(s,i)}}class n extends h{constructor(s,i){super(),this.errorHandler=(s,i)=>{console.log(`(Unit of SubscribeObject).send(${s}) ERROR:`,i)},this._order=0,this.isPaused=!1,this.isPipe=!1,this.observable=s,this.isPipe=!!i}subscribe(s,i){return this.listener=function(s){if(Array.isArray(s)){const i=[];for(let e=0;e<s.length;e++)i.push(t(s[e]));return s=>{for(let e=0;e<i.length;e++)i[e](s)}}return t(s)}(s),i&&(this.errorHandler=i),this}unsubscribe(){this.observable&&(this.observable.unSubscribe(this),this.observable=null,this.listener=null,this.chain.length=0)}send(s){try{this.flow.payload=s,this.flow.isBreak=!1,this.processValue(s)}catch(i){this.errorHandler(s,i)}}resume(){this.isPaused=!1}pause(){this.isPaused=!0}get order(){return this._order}set order(s){this._order=s}processValue(s){const i=this.listener;return i?this.observable&&!this.isPaused?this.isPipe?this.processChain(i):i(s):void 0:this.unsubscribe()}}class a{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((i=>{s(i.payload)&&(i.isAvailable=!0)}))}pushFilters(s){if(!Array.isArray(s))return this;for(let i=0;i<s.length;i++)this.filter(s[i]);return this}switch(){return new o(this)}processChain(s){const i=this.chain,e=this.flow,t=this.response;t.isOK=!1,t.payload=void 0,e.payload=s,e.isBreak=!1;try{for(let s=0;s<i.length;s++){if(e.isAvailable=!1,i[s](e),!e.isAvailable)return t;if(e.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=e.payload,t}addErrorHandler(s){this.errHandler=s}}class o extends r{}class u{constructor(s){this.value=s,this.listeners=[],this.isStop=!0,this.isKilled=!1,this.isProcess=!1,this.trash=[],this.filters=new a}addFilter(s){return s&&this.filters.addErrorHandler(s),this.filters}disable(){this.isStop=!1}enable(){this.isStop=!0}get isEnable(){return this.isStop}next(s){if(!this.isKilled&&this.isStop&&(this.filters.isEmpty||this.filters.processChain(s).isOK)){this.isProcess=!0,this.value=s;for(let i=0;i<this.listeners.length;i++)this.listeners[i].send(s);this.isProcess=!1,this.trash.length&&this.handleListenersForUnsubscribe()}}stream(s){if(!this.isKilled&&this.isStop)for(let i=0;i<s.length;i++)this.next(s[i])}handleListenersForUnsubscribe(){const s=this.trash.length;for(let i=0;i<s;i++)this.unSubscribe(this.trash[i]);this.trash.length=0}unSubscribe(s){this.isKilled||(this.isProcess&&s?this.trash.push(s):this.listeners&&e(this.listeners,s))}destroy(){this.value=null,this.unsubscribeAll(),this.listeners=null,this.isKilled=!0}unsubscribeAll(){this.isKilled||(this.listeners.length=0)}getValue(){if(!this.isKilled)return this.value}size(){return this.isKilled?0:this.listeners.length}subscribe(s,i){if(!this.isListener(s))return;const e=new n(this,!1);return this.addObserver(e,s,i),e}addObserver(s,i,e){s.subscribe(i,e),this.listeners.push(s)}isListener(s){return!this.isKilled&&!!s}pipe(){if(this.isKilled)return;const s=new n(this,!0);return this.listeners.push(s),s}get isDestroyed(){return this.isKilled}}class c extends n{constructor(s,i){super(s,i)}get order(){return this._order}set order(s){!this.observable||this.observable&&this.observable.isDestroyed?this._order=void 0:(this._order=s,this.observable.sortByOrder())}subscribe(s,i){return super.subscribe(s,i),this}setOnce(){return super.setOnce()}}const d=window;d.Observable=u,d.Collector=class{constructor(){this.list=[],this.isKilled=!1}collect(...s){this.isKilled||this.list.push(...s)}unsubscribe(s){this.isKilled||(s?.unsubscribe(),e(this.list,s))}unsubscribeAll(){if(!this.isKilled)for(;this.list.length>0;)this.unsubscribe(this.list.pop())}size(){return this.isKilled?0:this.list.length}destroy(){this.unsubscribeAll(),this.list.length=0,this.list=0,this.isKilled=!0}get isDestroyed(){return this.isKilled}},d.OrderedObservable=class extends u{constructor(){super(...arguments),this.sortDirection=s}setAscendingSort(){return this.sortDirection=s,this.sortByOrder()}setDescendingSort(){return this.sortDirection=i,this.sortByOrder()}sortByOrder(){return!this.isKilled&&(this.listeners.sort(this.sortDirection),!0)}subscribe(s,i){if(!this.isListener(s))return;const e=new c(this,!1);return this.addObserver(e,s,i),e}pipe(){if(this.isKilled)return;const s=new c(this,!0);return this.listeners.push(s),s}unSubscribe(s){this.isKilled||(this.isProcess&&s?this.trash.push(s):this.listeners&&function(s,i){const e=s.indexOf(i);-1!==e&&s.splice(e,1)}(this.listeners,s))}}})();
@@ -0,0 +1,8 @@
1
+ import { ICallback, IChainContainer } from "./Types";
2
+ export declare abstract class SwitchCase<T, P extends IChainContainer, W> {
3
+ protected pipe: P;
4
+ protected counter: number;
5
+ constructor(pipe: P);
6
+ case(condition: ICallback<any>): W;
7
+ pushCases(conditions: ICallback<any>[]): W;
8
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SwitchCase = void 0;
4
+ class SwitchCase {
5
+ pipe;
6
+ counter;
7
+ constructor(pipe) {
8
+ this.pipe = pipe;
9
+ this.counter = pipe.chain.length ? pipe.chain.length : 0;
10
+ }
11
+ case(condition) {
12
+ this.counter++;
13
+ const id = this.counter;
14
+ const chain = this.pipe.chain;
15
+ chain.push((data) => {
16
+ data.isAvailable = true;
17
+ if (condition(data.payload))
18
+ data.isBreak = true;
19
+ if (id === chain.length && !data.isBreak)
20
+ data.isAvailable = false;
21
+ });
22
+ return this;
23
+ }
24
+ pushCases(conditions) {
25
+ if (!Array.isArray(conditions))
26
+ return this;
27
+ for (let i = 0; i < conditions.length; i++)
28
+ this.case(conditions[i]);
29
+ return this;
30
+ }
31
+ }
32
+ exports.SwitchCase = SwitchCase;
@@ -1,7 +1,7 @@
1
1
  import { ICollector, ISubscriptionLike } from "./Types";
2
2
  export declare class Collector implements ICollector {
3
3
  protected list: ISubscriptionLike[];
4
- private _isDestroyed;
4
+ private isKilled;
5
5
  collect(...subscriptionLikeList: ISubscriptionLike[]): void;
6
6
  unsubscribe(subscriptionLike: ISubscriptionLike | undefined): void;
7
7
  unsubscribeAll(): void | null;
@@ -4,25 +4,25 @@ exports.Collector = void 0;
4
4
  const FunctionLibs_1 = require("./FunctionLibs");
5
5
  class Collector {
6
6
  list = [];
7
- _isDestroyed = false;
7
+ isKilled = false;
8
8
  collect(...subscriptionLikeList) {
9
- if (!this._isDestroyed)
9
+ if (!this.isKilled)
10
10
  this.list.push(...subscriptionLikeList);
11
11
  }
12
12
  unsubscribe(subscriptionLike) {
13
- if (this._isDestroyed)
13
+ if (this.isKilled)
14
14
  return;
15
15
  subscriptionLike?.unsubscribe();
16
16
  (0, FunctionLibs_1.quickDeleteFromArray)(this.list, subscriptionLike);
17
17
  }
18
18
  unsubscribeAll() {
19
- if (this._isDestroyed)
19
+ if (this.isKilled)
20
20
  return;
21
21
  while (this.list.length > 0)
22
22
  this.unsubscribe(this.list.pop());
23
23
  }
24
24
  size() {
25
- if (this._isDestroyed)
25
+ if (this.isKilled)
26
26
  return 0;
27
27
  return this.list.length;
28
28
  }
@@ -30,10 +30,10 @@ class Collector {
30
30
  this.unsubscribeAll();
31
31
  this.list.length = 0;
32
32
  this.list = 0;
33
- this._isDestroyed = true;
33
+ this.isKilled = true;
34
34
  }
35
35
  get isDestroyed() {
36
- return this._isDestroyed;
36
+ return this.isKilled;
37
37
  }
38
38
  }
39
39
  exports.Collector = Collector;
@@ -1,20 +1,17 @@
1
- import { ICallback, IChainCallback, IErrorCallback, IFilter, IFilterCase, IFilterPayload, IFilterResponse, IFilterSetup, IFilterSwitch } from "./Types";
1
+ import { ICallback, IErrorCallback, IFilter, IFilterChainCallback, IFilterPayload, IFilterResponse, IFilterSetup, IFilterSwitch } from "./Types";
2
+ import { SwitchCase } from "./AbstractSwitchCase";
2
3
  export declare class FilterCollection<T> implements IFilter<T>, IFilterSwitch<T> {
3
- chainHandlers: IChainCallback[];
4
- pipeData: IFilterPayload;
4
+ chain: IFilterChainCallback[];
5
+ flow: IFilterPayload;
5
6
  response: IFilterResponse;
6
- private errorHandler;
7
+ private errHandler;
7
8
  get isEmpty(): boolean;
9
+ private push;
8
10
  filter(condition: ICallback<any>): IFilterSetup<T>;
9
11
  pushFilters(conditions: ICallback<any>[]): IFilterSetup<T>;
10
12
  switch(): FilterSwitchCase<T>;
11
13
  processChain(value: T): IFilterResponse;
12
14
  addErrorHandler(errorHandler: IErrorCallback): void;
13
15
  }
14
- export declare class FilterSwitchCase<T> implements IFilterCase<T> {
15
- private pipe;
16
- private caseCounter;
17
- constructor(pipe: FilterCollection<T>);
18
- case(condition: ICallback<any>): IFilterCase<T>;
19
- pushCases(conditions: ICallback<any>[]): IFilterCase<T>;
16
+ export declare class FilterSwitchCase<T> extends SwitchCase<T, FilterCollection<T>, IFilter<T>> {
20
17
  }
@@ -1,21 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FilterSwitchCase = exports.FilterCollection = void 0;
4
+ const AbstractSwitchCase_1 = require("./AbstractSwitchCase");
4
5
  class FilterCollection {
5
- chainHandlers = [];
6
- pipeData = { isBreakChain: false, isAvailable: false, payload: null };
6
+ chain = [];
7
+ flow = { isBreak: false, isAvailable: false, payload: null };
7
8
  response = { isOK: false, payload: undefined };
8
- errorHandler;
9
+ errHandler;
9
10
  get isEmpty() {
10
- return !this.chainHandlers.length;
11
+ return !this.chain.length;
12
+ }
13
+ push(callback) {
14
+ this.chain.push(callback);
15
+ return this;
11
16
  }
12
17
  filter(condition) {
13
- const data = this.pipeData;
14
- this.chainHandlers.push(() => {
18
+ return this.push((data) => {
15
19
  if (condition(data.payload))
16
20
  data.isAvailable = true;
17
21
  });
18
- return this;
19
22
  }
20
23
  pushFilters(conditions) {
21
24
  if (!Array.isArray(conditions))
@@ -28,26 +31,26 @@ class FilterCollection {
28
31
  return new FilterSwitchCase(this);
29
32
  }
30
33
  processChain(value) {
31
- const chain = this.chainHandlers;
32
- const data = this.pipeData;
34
+ const chain = this.chain;
35
+ const data = this.flow;
33
36
  const response = this.response;
34
37
  response.isOK = false;
35
38
  response.payload = undefined;
36
39
  data.payload = value;
37
- data.isBreakChain = false;
40
+ data.isBreak = false;
38
41
  try {
39
42
  for (let i = 0; i < chain.length; i++) {
40
43
  data.isAvailable = false;
41
- chain[i]();
44
+ chain[i](data);
42
45
  if (!data.isAvailable)
43
46
  return response;
44
- if (data.isBreakChain)
47
+ if (data.isBreak)
45
48
  break;
46
49
  }
47
50
  }
48
51
  catch (err) {
49
- if (this.errorHandler) {
50
- this.errorHandler(err, "Filter.processChain ERROR:");
52
+ if (this.errHandler) {
53
+ this.errHandler(err, "Filter.processChain ERROR:");
51
54
  }
52
55
  else {
53
56
  console.log("Filter.processChain ERROR:", err);
@@ -59,37 +62,10 @@ class FilterCollection {
59
62
  return response;
60
63
  }
61
64
  addErrorHandler(errorHandler) {
62
- this.errorHandler = errorHandler;
65
+ this.errHandler = errorHandler;
63
66
  }
64
67
  }
65
68
  exports.FilterCollection = FilterCollection;
66
- class FilterSwitchCase {
67
- pipe;
68
- caseCounter;
69
- constructor(pipe) {
70
- this.pipe = pipe;
71
- this.caseCounter = pipe.chainHandlers.length ? pipe.chainHandlers.length : 0;
72
- }
73
- case(condition) {
74
- this.caseCounter++;
75
- const id = this.caseCounter;
76
- const data = this.pipe.pipeData;
77
- const chain = this.pipe.chainHandlers;
78
- chain.push(() => {
79
- data.isAvailable = true;
80
- if (condition(data.payload))
81
- data.isBreakChain = true;
82
- if (id === chain.length && !data.isBreakChain)
83
- data.isAvailable = false;
84
- });
85
- return this;
86
- }
87
- pushCases(conditions) {
88
- if (!Array.isArray(conditions))
89
- return this;
90
- for (let i = 0; i < conditions.length; i++)
91
- this.case(conditions[i]);
92
- return this;
93
- }
69
+ class FilterSwitchCase extends AbstractSwitchCase_1.SwitchCase {
94
70
  }
95
71
  exports.FilterSwitchCase = FilterSwitchCase;
@@ -3,11 +3,11 @@ import { SubscribeObject } from "./SubscribeObject";
3
3
  export declare class Observable<T> implements IObserver<T>, IStream<T>, IAddFilter<T> {
4
4
  private value;
5
5
  protected listeners: ISubscribeObject<T>[];
6
- private _isEnable;
7
- protected _isDestroyed: boolean;
8
- protected isNextProcess: boolean;
9
- protected listenersForUnsubscribe: ISubscriptionLike[];
10
- private filterCase;
6
+ private isStop;
7
+ protected isKilled: boolean;
8
+ protected isProcess: boolean;
9
+ protected trash: ISubscriptionLike[];
10
+ private filters;
11
11
  constructor(value: T);
12
12
  addFilter(errorHandler?: IErrorCallback): IFilterSetup<T>;
13
13
  disable(): void;
@@ -23,7 +23,7 @@ export declare class Observable<T> implements IObserver<T>, IStream<T>, IAddFilt
23
23
  size(): number;
24
24
  subscribe(observer: ISubscribeGroup<T>, errorHandler?: IErrorCallback): ISubscriptionLike | undefined;
25
25
  protected addObserver(subscribeObject: SubscribeObject<T>, observer: ISubscribeGroup<T>, errorHandler?: IErrorCallback): void;
26
- protected isSubsValid(listener: ISubscribeGroup<T>): boolean;
26
+ protected isListener(listener: ISubscribeGroup<T>): boolean;
27
27
  pipe(): ISetup<T> | undefined;
28
28
  get isDestroyed(): boolean;
29
29
  }
@@ -7,64 +7,64 @@ const FilterCollection_1 = require("./FilterCollection");
7
7
  class Observable {
8
8
  value;
9
9
  listeners = [];
10
- _isEnable = true;
11
- _isDestroyed = false;
12
- isNextProcess = false;
13
- listenersForUnsubscribe = [];
14
- filterCase = new FilterCollection_1.FilterCollection();
10
+ isStop = true;
11
+ isKilled = false;
12
+ isProcess = false;
13
+ trash = [];
14
+ filters = new FilterCollection_1.FilterCollection();
15
15
  constructor(value) {
16
16
  this.value = value;
17
17
  }
18
18
  addFilter(errorHandler) {
19
19
  if (errorHandler) {
20
- this.filterCase.addErrorHandler(errorHandler);
20
+ this.filters.addErrorHandler(errorHandler);
21
21
  }
22
- return this.filterCase;
22
+ return this.filters;
23
23
  }
24
24
  disable() {
25
- this._isEnable = false;
25
+ this.isStop = false;
26
26
  }
27
27
  enable() {
28
- this._isEnable = true;
28
+ this.isStop = true;
29
29
  }
30
30
  get isEnable() {
31
- return this._isEnable;
31
+ return this.isStop;
32
32
  }
33
33
  next(value) {
34
- if (this._isDestroyed)
34
+ if (this.isKilled)
35
35
  return;
36
- if (!this._isEnable)
36
+ if (!this.isStop)
37
37
  return;
38
- if (!this.filterCase.isEmpty) {
39
- if (!this.filterCase.processChain(value).isOK)
38
+ if (!this.filters.isEmpty) {
39
+ if (!this.filters.processChain(value).isOK)
40
40
  return;
41
41
  }
42
- this.isNextProcess = true;
42
+ this.isProcess = true;
43
43
  this.value = value;
44
44
  for (let i = 0; i < this.listeners.length; i++)
45
45
  this.listeners[i].send(value);
46
- this.isNextProcess = false;
47
- this.listenersForUnsubscribe.length && this.handleListenersForUnsubscribe();
46
+ this.isProcess = false;
47
+ this.trash.length && this.handleListenersForUnsubscribe();
48
48
  }
49
49
  stream(values) {
50
- if (this._isDestroyed)
50
+ if (this.isKilled)
51
51
  return;
52
- if (!this._isEnable)
52
+ if (!this.isStop)
53
53
  return;
54
54
  for (let i = 0; i < values.length; i++)
55
55
  this.next(values[i]);
56
56
  }
57
57
  handleListenersForUnsubscribe() {
58
- const length = this.listenersForUnsubscribe.length;
58
+ const length = this.trash.length;
59
59
  for (let i = 0; i < length; i++)
60
- this.unSubscribe(this.listenersForUnsubscribe[i]);
61
- this.listenersForUnsubscribe.length = 0;
60
+ this.unSubscribe(this.trash[i]);
61
+ this.trash.length = 0;
62
62
  }
63
63
  unSubscribe(listener) {
64
- if (this._isDestroyed)
64
+ if (this.isKilled)
65
65
  return;
66
- if (this.isNextProcess && listener) {
67
- this.listenersForUnsubscribe.push(listener);
66
+ if (this.isProcess && listener) {
67
+ this.trash.push(listener);
68
68
  return;
69
69
  }
70
70
  this.listeners && !(0, FunctionLibs_1.quickDeleteFromArray)(this.listeners, listener);
@@ -73,25 +73,25 @@ class Observable {
73
73
  this.value = null;
74
74
  this.unsubscribeAll();
75
75
  this.listeners = null;
76
- this._isDestroyed = true;
76
+ this.isKilled = true;
77
77
  }
78
78
  unsubscribeAll() {
79
- if (this._isDestroyed)
79
+ if (this.isKilled)
80
80
  return;
81
81
  this.listeners.length = 0;
82
82
  }
83
83
  getValue() {
84
- if (this._isDestroyed)
84
+ if (this.isKilled)
85
85
  return undefined;
86
86
  return this.value;
87
87
  }
88
88
  size() {
89
- if (this._isDestroyed)
89
+ if (this.isKilled)
90
90
  return 0;
91
91
  return this.listeners.length;
92
92
  }
93
93
  subscribe(observer, errorHandler) {
94
- if (!this.isSubsValid(observer))
94
+ if (!this.isListener(observer))
95
95
  return undefined;
96
96
  const subscribeObject = new SubscribeObject_1.SubscribeObject(this, false);
97
97
  this.addObserver(subscribeObject, observer, errorHandler);
@@ -101,20 +101,20 @@ class Observable {
101
101
  subscribeObject.subscribe(observer, errorHandler);
102
102
  this.listeners.push(subscribeObject);
103
103
  }
104
- isSubsValid(listener) {
105
- if (this._isDestroyed)
104
+ isListener(listener) {
105
+ if (this.isKilled)
106
106
  return false;
107
107
  return !!listener;
108
108
  }
109
109
  pipe() {
110
- if (this._isDestroyed)
110
+ if (this.isKilled)
111
111
  return undefined;
112
112
  const subscribeObject = new SubscribeObject_1.SubscribeObject(this, true);
113
113
  this.listeners.push(subscribeObject);
114
114
  return subscribeObject;
115
115
  }
116
116
  get isDestroyed() {
117
- return this._isDestroyed;
117
+ return this.isKilled;
118
118
  }
119
119
  }
120
120
  exports.Observable = Observable;
@@ -15,30 +15,30 @@ class OrderedObservable extends Observable_1.Observable {
15
15
  return this.sortByOrder();
16
16
  }
17
17
  sortByOrder() {
18
- if (this._isDestroyed)
18
+ if (this.isKilled)
19
19
  return false;
20
20
  this.listeners.sort(this.sortDirection);
21
21
  return true;
22
22
  }
23
23
  subscribe(listener, errorHandler) {
24
- if (!this.isSubsValid(listener))
24
+ if (!this.isListener(listener))
25
25
  return undefined;
26
26
  const subscribeObject = new OrderedSubscribeObject_1.OrderedSubscribeObject(this, false);
27
27
  this.addObserver(subscribeObject, listener, errorHandler);
28
28
  return subscribeObject;
29
29
  }
30
30
  pipe() {
31
- if (this._isDestroyed)
31
+ if (this.isKilled)
32
32
  return undefined;
33
33
  const subscribeObject = new OrderedSubscribeObject_1.OrderedSubscribeObject(this, true);
34
34
  this.listeners.push(subscribeObject);
35
35
  return subscribeObject;
36
36
  }
37
37
  unSubscribe(listener) {
38
- if (this._isDestroyed)
38
+ if (this.isKilled)
39
39
  return;
40
- if (this.isNextProcess && listener) {
41
- this.listenersForUnsubscribe.push(listener);
40
+ if (this.isProcess && listener) {
41
+ this.trash.push(listener);
42
42
  return;
43
43
  }
44
44
  this.listeners && !(0, FunctionLibs_1.deleteFromArray)(this.listeners, listener);
@@ -1,5 +1,5 @@
1
1
  import { SubscribeObject } from "./SubscribeObject";
2
- import { ICallback, IErrorCallback, IListener, IOrdered, IOrderedSetup, IOrderedSubscribe, IOrderedSubscriptionLike, ISetObservableValue } from "./Types";
2
+ import { IErrorCallback, IListener, IOrdered, IOrderedSetup, IOrderedSubscribe, IOrderedSubscriptionLike, ISetObservableValue } from "./Types";
3
3
  import { OrderedObservable } from "./OrderedObservable";
4
4
  export declare class OrderedSubscribeObject<T> extends SubscribeObject<T> implements IOrderedSetup<T> {
5
5
  constructor(observable: OrderedObservable<T> | IOrdered<T>, isPipe?: boolean);
@@ -7,9 +7,4 @@ export declare class OrderedSubscribeObject<T> extends SubscribeObject<T> implem
7
7
  set order(value: number);
8
8
  subscribe(observer: IListener<T> | ISetObservableValue, errorHandler?: IErrorCallback): IOrderedSubscriptionLike;
9
9
  setOnce(): IOrderedSubscribe<T>;
10
- unsubscribeByNegative(condition: ICallback<any>): IOrderedSetup<T>;
11
- unsubscribeByPositive(condition: ICallback<any>): IOrderedSetup<T>;
12
- emitByNegative(condition: ICallback<any>): IOrderedSetup<T>;
13
- emitByPositive(condition: ICallback<any>): IOrderedSetup<T>;
14
- emitMatch(condition: ICallback<any>): IOrderedSetup<T>;
15
10
  }
@@ -25,20 +25,5 @@ class OrderedSubscribeObject extends SubscribeObject_1.SubscribeObject {
25
25
  setOnce() {
26
26
  return super.setOnce();
27
27
  }
28
- unsubscribeByNegative(condition) {
29
- return super.unsubscribeByNegative(condition);
30
- }
31
- unsubscribeByPositive(condition) {
32
- return super.unsubscribeByPositive(condition);
33
- }
34
- emitByNegative(condition) {
35
- return super.emitByNegative(condition);
36
- }
37
- emitByPositive(condition) {
38
- return super.emitByPositive(condition);
39
- }
40
- emitMatch(condition) {
41
- return super.emitMatch(condition);
42
- }
43
28
  }
44
29
  exports.OrderedSubscribeObject = OrderedSubscribeObject;
@@ -1,28 +1,20 @@
1
1
  import { ICallback, IChainCallback, IErrorCallback, IListener, IPipeCase, IPipePayload, ISetObservableValue, ISetup, ISubscribe, ISubscriptionLike } from "./Types";
2
+ import { SwitchCase } from "./AbstractSwitchCase";
2
3
  export declare abstract class Pipe<T> implements ISubscribe<T> {
3
- chainHandlers: IChainCallback[];
4
- pipeData: IPipePayload;
4
+ chain: IChainCallback[];
5
+ flow: IPipePayload;
5
6
  abstract subscribe(listener: IListener<T> | ISetObservableValue, errorHandler?: IErrorCallback): ISubscriptionLike | undefined;
7
+ private push;
6
8
  setOnce(): ISubscribe<T>;
7
- unsubscribeByNegative(condition: ICallback<T>): ISetup<T>;
8
- unsubscribeByPositive(condition: ICallback<T>): ISetup<T>;
9
9
  unsubscribeBy(condition: ICallback<T>): ISetup<T>;
10
- emitByNegative(condition: ICallback<T>): ISetup<T>;
11
- emitByPositive(condition: ICallback<T>): ISetup<T>;
12
10
  refine(condition: ICallback<T>): ISetup<T>;
13
11
  pushRefiners(conditions: ICallback<any>[]): ISetup<T>;
14
- emitMatch(condition: ICallback<T>): ISetup<T>;
15
- switch(): SwitchCase<T>;
12
+ switch(): PipeSwitchCase<T>;
16
13
  then<K>(condition: ICallback<T>): ISetup<K>;
17
14
  serialize(): ISetup<string>;
18
15
  deserialize<K>(): ISetup<K>;
19
16
  processChain(listener: IListener<T>): void;
20
17
  }
21
- export declare class SwitchCase<T> implements ISubscribe<T>, IPipeCase<T> {
22
- private pipe;
23
- private caseCounter;
24
- constructor(pipe: Pipe<T>);
18
+ export declare class PipeSwitchCase<T> extends SwitchCase<T, Pipe<T>, IPipeCase<T>> implements ISubscribe<T> {
25
19
  subscribe(listener: IListener<T> | ISetObservableValue, errorHandler?: IErrorCallback): ISubscriptionLike | undefined;
26
- case(condition: ICallback<any>): IPipeCase<T> & ISubscribe<T>;
27
- pushCases(conditions: ICallback<any>[]): IPipeCase<T> & ISubscribe<T>;
28
20
  }
@@ -1,147 +1,82 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SwitchCase = exports.Pipe = void 0;
3
+ exports.PipeSwitchCase = exports.Pipe = void 0;
4
+ const AbstractSwitchCase_1 = require("./AbstractSwitchCase");
4
5
  class Pipe {
5
- chainHandlers = [];
6
- pipeData = { isBreakChain: false, isNeedUnsubscribe: false, isAvailable: false, payload: null };
7
- setOnce() {
8
- const data = this.pipeData;
9
- this.chainHandlers.push(() => {
10
- this.listener(data.payload);
11
- data.isNeedUnsubscribe = true;
12
- });
6
+ chain = [];
7
+ flow = { isBreak: false, isUnsubscribe: false, isAvailable: false, payload: null };
8
+ push(callback) {
9
+ this.chain.push(callback);
13
10
  return this;
14
11
  }
15
- unsubscribeByNegative(condition) {
16
- const data = this.pipeData;
17
- this.chainHandlers.push(() => {
18
- data.isAvailable = true;
19
- if (!condition(data.payload))
20
- data.isNeedUnsubscribe = true;
12
+ setOnce() {
13
+ return this.push((data) => {
14
+ this.listener(data.payload);
15
+ data.isUnsubscribe = true;
21
16
  });
22
- return this;
23
17
  }
24
- unsubscribeByPositive(condition) {
25
- const data = this.pipeData;
26
- this.chainHandlers.push(() => {
18
+ unsubscribeBy(condition) {
19
+ return this.push((data) => {
27
20
  data.isAvailable = true;
28
21
  if (condition(data.payload))
29
- data.isNeedUnsubscribe = true;
22
+ data.isUnsubscribe = true;
30
23
  });
31
- return this;
32
24
  }
33
- unsubscribeBy(condition) {
34
- return this.unsubscribeByPositive(condition);
35
- }
36
- emitByNegative(condition) {
37
- const data = this.pipeData;
38
- this.chainHandlers.push(() => {
39
- if (!condition(data.payload))
40
- data.isAvailable = true;
41
- });
42
- return this;
43
- }
44
- emitByPositive(condition) {
45
- const data = this.pipeData;
46
- this.chainHandlers.push(() => {
25
+ refine(condition) {
26
+ return this.push((data) => {
47
27
  if (condition(data.payload))
48
28
  data.isAvailable = true;
49
29
  });
50
- return this;
51
- }
52
- refine(condition) {
53
- return this.emitByPositive(condition);
54
30
  }
55
31
  pushRefiners(conditions) {
56
32
  if (!Array.isArray(conditions))
57
33
  return this;
58
34
  for (let i = 0; i < conditions.length; i++)
59
- this.emitByPositive(conditions[i]);
60
- return this;
61
- }
62
- emitMatch(condition) {
63
- const data = this.pipeData;
64
- this.chainHandlers.push(() => {
65
- if (condition(data.payload) == data.payload)
66
- data.isAvailable = true;
67
- });
35
+ this.refine(conditions[i]);
68
36
  return this;
69
37
  }
70
38
  switch() {
71
- return new SwitchCase(this);
39
+ return new PipeSwitchCase(this);
72
40
  }
73
41
  then(condition) {
74
- const data = this.pipeData;
75
- this.chainHandlers.push(() => {
42
+ return this.push((data) => {
76
43
  data.payload = condition(data.payload);
77
44
  data.isAvailable = true;
78
45
  });
79
- return this;
80
46
  }
81
47
  serialize() {
82
- const data = this.pipeData;
83
- this.chainHandlers.push(() => {
48
+ return this.push((data) => {
84
49
  data.payload = JSON.stringify(data.payload);
85
50
  data.isAvailable = true;
86
51
  });
87
- return this;
88
52
  }
89
53
  deserialize() {
90
- const data = this.pipeData;
91
- this.chainHandlers.push(() => {
54
+ return this.push((data) => {
92
55
  data.payload = JSON.parse(data.payload);
93
56
  data.isAvailable = true;
94
57
  });
95
- return this;
96
58
  }
97
59
  processChain(listener) {
98
- const chain = this.chainHandlers;
99
- const data = this.pipeData;
60
+ const chain = this.chain;
61
+ const data = this.flow;
100
62
  for (let i = 0; i < chain.length; i++) {
101
- data.isNeedUnsubscribe = false;
63
+ data.isUnsubscribe = false;
102
64
  data.isAvailable = false;
103
- chain[i]();
104
- if (data.isNeedUnsubscribe)
65
+ chain[i](data);
66
+ if (data.isUnsubscribe)
105
67
  return this.unsubscribe();
106
68
  if (!data.isAvailable)
107
69
  return;
108
- if (data.isBreakChain)
70
+ if (data.isBreak)
109
71
  break;
110
72
  }
111
73
  return listener(data.payload);
112
74
  }
113
75
  }
114
76
  exports.Pipe = Pipe;
115
- class SwitchCase {
116
- pipe;
117
- caseCounter;
118
- constructor(pipe) {
119
- this.pipe = pipe;
120
- this.caseCounter = pipe.chainHandlers.length ? pipe.chainHandlers.length : 0;
121
- }
77
+ class PipeSwitchCase extends AbstractSwitchCase_1.SwitchCase {
122
78
  subscribe(listener, errorHandler) {
123
79
  return this.pipe.subscribe(listener, errorHandler);
124
80
  }
125
- case(condition) {
126
- this.caseCounter++;
127
- const id = this.caseCounter;
128
- const data = this.pipe.pipeData;
129
- const chain = this.pipe.chainHandlers;
130
- chain.push(() => {
131
- data.isAvailable = true;
132
- if (condition(data.payload))
133
- data.isBreakChain = true;
134
- if (id === chain.length && !data.isBreakChain)
135
- data.isAvailable = false;
136
- });
137
- return this;
138
- }
139
- pushCases(conditions) {
140
- if (!Array.isArray(conditions))
141
- return this;
142
- for (let i = 0; i < conditions.length; i++)
143
- this.case(conditions[i]);
144
- return this;
145
- }
146
81
  }
147
- exports.SwitchCase = SwitchCase;
82
+ exports.PipeSwitchCase = PipeSwitchCase;
@@ -28,12 +28,12 @@ class SubscribeObject extends Pipe_1.Pipe {
28
28
  this.observable.unSubscribe(this);
29
29
  this.observable = null;
30
30
  this.listener = null;
31
- this.chainHandlers.length = 0;
31
+ this.chain.length = 0;
32
32
  }
33
33
  send(value) {
34
34
  try {
35
- this.pipeData.payload = value;
36
- this.pipeData.isBreakChain = false;
35
+ this.flow.payload = value;
36
+ this.flow.isBreak = false;
37
37
  this.processValue(value);
38
38
  }
39
39
  catch (err) {
@@ -57,7 +57,7 @@ class SubscribeObject extends Pipe_1.Pipe {
57
57
  if (!listener)
58
58
  return this.unsubscribe();
59
59
  if (!this.observable)
60
- return this.unsubscribe();
60
+ return;
61
61
  if (this.isPaused)
62
62
  return;
63
63
  if (!this.isPipe)
@@ -1,4 +1,4 @@
1
- import { SwitchCase } from "./Pipe";
1
+ import { PipeSwitchCase } from "./Pipe";
2
2
  import { FilterSwitchCase } from "./FilterCollection";
3
3
  export type ICallback<T> = (value?: T) => any;
4
4
  export type IErrorCallback = (errorData: any, errorMessage: any) => void;
@@ -14,10 +14,10 @@ export type IOrder = {
14
14
  order: number;
15
15
  };
16
16
  export type ISwitch<T> = {
17
- switch(): SwitchCase<T>;
17
+ switch(): PipeSwitchCase<T>;
18
18
  };
19
19
  export type IOrderedSwitch<T> = {
20
- switch(): SwitchCase<T>;
20
+ switch(): PipeSwitchCase<T>;
21
21
  };
22
22
  export type IOnce<T> = {
23
23
  setOnce(): ISubscribe<T>;
@@ -31,8 +31,8 @@ export type ISetObservableValue = {
31
31
  export type ISubscriptionLike = {
32
32
  unsubscribe(): void;
33
33
  };
34
- export type ISetup<T> = IUnsubscribeByNegative<T> & IUnsubscribeByPositive<T> & IEmitByNegative<T> & IEmitByPositive<T> & IEmitMatchCondition<T> & IOnce<T> & ISwitch<T> & ITransform<T> & ISerialisation & ISubscribe<T>;
35
- export type IOrderedSetup<T> = IOrderedUnsubscribeByNegative<T> & IOrderedUnsubscribeByPositive<T> & IOrderedEmitByNegative<T> & IOrderedEmitByPositive<T> & IOrderedEmitMatchCondition<T> & IOrderedOnce<T> & IOrderedSwitch<T> & IOrderedTransform<T> & IOrderedSerialisation & IOrderedSubscribe<T>;
34
+ export type ISetup<T> = IUnsubscribeByPositive<T> & IEmitByPositive<T> & IOnce<T> & ISwitch<T> & ITransform<T> & ISerialisation & ISubscribe<T>;
35
+ export type IOrderedSetup<T> = IOrderedUnsubscribeByPositive<T> & IOrderedEmitByPositive<T> & IOrderedOnce<T> & IOrderedSwitch<T> & IOrderedTransform<T> & IOrderedSerialisation & IOrderedSubscribe<T>;
36
36
  export type ISubscribeObject<T> = ISubscriptionLike & IPause & IOrder & ISend<T> & ISetup<T>;
37
37
  export type ISubscribeCounter = {
38
38
  size(): number;
@@ -70,11 +70,9 @@ export type IOrderedUnsubscribeByNegative<T> = {
70
70
  unsubscribeByNegative(condition: ICallback<T>): IOrderedSetup<T>;
71
71
  };
72
72
  export type IUnsubscribeByPositive<T> = {
73
- unsubscribeByPositive(condition: ICallback<T>): ISetup<T>;
74
73
  unsubscribeBy(condition: ICallback<T>): ISetup<T>;
75
74
  };
76
75
  export type IOrderedUnsubscribeByPositive<T> = {
77
- unsubscribeByPositive(condition: ICallback<T>): IOrderedSetup<T>;
78
76
  unsubscribeBy(condition: ICallback<T>): ISetup<T>;
79
77
  };
80
78
  export type IEmitByNegative<T> = {
@@ -84,7 +82,6 @@ export type IOrderedEmitByNegative<T> = {
84
82
  emitByNegative(condition: ICallback<T>): IOrderedSetup<T>;
85
83
  };
86
84
  export type IEmitByPositive<T> = {
87
- emitByPositive(condition: ICallback<T>): ISetup<T>;
88
85
  refine(condition: ICallback<T>): ISetup<T>;
89
86
  pushRefiners(conditions: ICallback<T>[]): ISetup<T>;
90
87
  };
@@ -96,7 +93,6 @@ export type ISerialisation = {
96
93
  deserialize<K>(): ISetup<K>;
97
94
  };
98
95
  export type IOrderedEmitByPositive<T> = {
99
- emitByPositive(condition: ICallback<any>): IOrderedSetup<T>;
100
96
  refine(condition: ICallback<any>): ISetup<T>;
101
97
  pushRefiners(conditions: ICallback<any>[]): ISetup<T>;
102
98
  };
@@ -126,14 +122,17 @@ export type IOrderedSubscriptionLike = (ISubscriptionLike & IOrder);
126
122
  export type IOrderedSubscribe<T> = {
127
123
  subscribe(listener: IListener<T>, errorHandler?: IErrorCallback): IOrderedSubscriptionLike;
128
124
  };
125
+ export type IChainContainer = {
126
+ chain: any[];
127
+ };
129
128
  export type IPipePayload = {
130
- isBreakChain: boolean;
131
- isNeedUnsubscribe: boolean;
129
+ isBreak: boolean;
130
+ isUnsubscribe: boolean;
132
131
  isAvailable: boolean;
133
132
  payload: any;
134
133
  };
135
- export type IChainCallback = () => void;
136
- export type IPipeCase<T> = {
134
+ export type IChainCallback = (data: IPipePayload) => void;
135
+ export type IPipeCase<T> = ISubscribe<T> & {
137
136
  case(condition: ICallback<any>): IPipeCase<T> & ISubscribe<T>;
138
137
  pushCases(conditions: ICallback<any>[]): IPipeCase<T> & ISubscribe<T>;
139
138
  };
@@ -155,10 +154,11 @@ export type IFilterCase<T> = {
155
154
  pushCases(conditions: ICallback<any>[]): IFilterCase<T>;
156
155
  };
157
156
  export type IFilterPayload = {
158
- isBreakChain: boolean;
157
+ isBreak: boolean;
159
158
  isAvailable: boolean;
160
159
  payload: any;
161
160
  };
161
+ export type IFilterChainCallback = (data: IFilterPayload) => void;
162
162
  export type IFilterResponse = {
163
163
  isOK: boolean;
164
164
  payload: any;