evg_observable 1.9.49 → 1.10.50
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 +29 -8
- package/package.json +1 -1
- package/repo/evg_observable.js +1 -1
- package/src/outLib/{Filter.d.ts → FilterCollection.d.ts} +4 -2
- package/src/outLib/{Filter.js → FilterCollection.js} +17 -3
- package/src/outLib/Observable.js +2 -2
- package/src/outLib/OrderedSubscribeObject.d.ts +3 -1
- package/src/outLib/OrderedSubscribeObject.js +6 -0
- package/src/outLib/Pipe.d.ts +3 -0
- package/src/outLib/Pipe.js +17 -0
- package/src/outLib/Types.d.ts +8 -1
package/README.md
CHANGED
|
@@ -444,6 +444,14 @@ const menFilter = (person: Person) => person.gender === GENDER.MAN;
|
|
|
444
444
|
const womenFilter = (person: Person) => person.gender === GENDER.WOMAN;
|
|
445
445
|
const blondFilter = (person: Person) => person.hairColor === HAIR.BLOND;
|
|
446
446
|
const blackFilter = (person: Person) => person.hairColor === HAIR.BLACK;
|
|
447
|
+
const personValidationFilters = [
|
|
448
|
+
(person: Person) => !!person,
|
|
449
|
+
(person: Person) => "name" in person,
|
|
450
|
+
(person: Person) => "age" in person,
|
|
451
|
+
(person: Person) => "gender" in person,
|
|
452
|
+
(person: Person) => "major" in person,
|
|
453
|
+
(person: Person) => "hairColor" in person,
|
|
454
|
+
];
|
|
447
455
|
|
|
448
456
|
// Callback function to execute when some man is ready to work
|
|
449
457
|
const manReadyToWork = (worker: Person) => {
|
|
@@ -462,14 +470,20 @@ const blondAndBlack = (person: Person) => {
|
|
|
462
470
|
|
|
463
471
|
// Apply the filters to men$ and women$
|
|
464
472
|
men$.addFilter()
|
|
473
|
+
.pushFilters(personValidationFilters)
|
|
465
474
|
.filter(menFilter);
|
|
466
475
|
|
|
467
476
|
women$.addFilter()
|
|
477
|
+
.pushFilters(personValidationFilters)
|
|
468
478
|
.filter(womenFilter);
|
|
469
479
|
|
|
470
480
|
// Subscribe the callback function to the created Observables
|
|
471
|
-
men$.
|
|
472
|
-
|
|
481
|
+
men$.pipe()
|
|
482
|
+
.pushRefiners(personValidationFilters)
|
|
483
|
+
.subscribe(manReadyToWork);
|
|
484
|
+
women$.pipe()
|
|
485
|
+
.pushRefiners(personValidationFilters)
|
|
486
|
+
.subscribe(womanReadyToWork);
|
|
473
487
|
|
|
474
488
|
// Stream the list of people by applying the age filters
|
|
475
489
|
personal$.pipe()
|
|
@@ -549,20 +563,27 @@ event handling a breeze.
|
|
|
549
563
|
| `.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 |
|
|
550
564
|
| `.emitByNegative(*condition)` | pipe object | observable will send a value to the listener only if condition returns "false", there is no automatic unsubscription |
|
|
551
565
|
| `.emitByPositive(*condition)` | pipe object | observable will send a value to the listener only if condition returns "true", there is no automatic unsubscription |
|
|
566
|
+
| `.refine(*condition)` | pipe object | observable will send a value to the listener only if condition returns "true", there is no automatic unsubscription |
|
|
567
|
+
| `.pushRefiners(*conditions)` | pipe object | This method allows you to add a group of conditions for filtering data in the pipeline chain. |
|
|
552
568
|
| `.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 |
|
|
553
569
|
| `.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. |
|
|
554
570
|
| `.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". |
|
|
571
|
+
| `.pushCases(*conditions)` | PipeCase object | This method allows you to add a group of conditions for filtering cases data in the pipeline chain. |
|
|
555
572
|
| `.subscribe(listener)` | subscriber | subscribe listener to observable |
|
|
573
|
+
|
|
556
574
|
_*condition_ - this is a function that should return a value that will affect the behavior of the subscriber
|
|
557
575
|
|
|
558
576
|
### Inbound filters
|
|
559
577
|
|
|
560
|
-
| Method
|
|
561
|
-
|
|
562
|
-
| `.addFilter()`
|
|
563
|
-
| `.filter(*condition)`
|
|
564
|
-
| `.
|
|
565
|
-
| `.
|
|
578
|
+
| Method | Will Return | Description |
|
|
579
|
+
|:----------------------------|:---------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
580
|
+
| `.addFilter()` | InboundFilter object | Transitions the Observable into the mode of adding inbound filters. |
|
|
581
|
+
| `.filter(*condition)` | InboundFilter object | Part of the filter chain that operates on the principle of "AND". If the condition returns `true`, the filter passes the data along the chain. |
|
|
582
|
+
| `.pushFilters(*conditions)` | InboundFilter object | This method allows you to add a group of conditions for filtering data in the chain. |
|
|
583
|
+
| `.switch()` | InboundFilter object | Transitions the filter into switch-case mode. In this mode, only the first condition that returns a positive result is triggered, and all others are ignored.
|
|
584
|
+
| `.case(*condition)` | InboundFilter object | Adds a condition to the chain of cases that operate on the principle of "OR". This is different from other filter methods which, when chained, operate on the principle of "AND". |
|
|
585
|
+
| `.pushCases(*conditions)` | InboundFilter object | This method allows you to add a group of conditions for filtering cases data in the chain. |
|
|
586
|
+
|
|
566
587
|
_*condition_ - this is a function that should return a value that will affect the behavior of the subscriber
|
|
567
588
|
|
|
568
589
|
### Observable subscriber
|
package/package.json
CHANGED
package/repo/evg_observable.js
CHANGED
|
@@ -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}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}emitMatch(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)==e.payload&&(e.isAvailable=!0)})),this}switch(){return new n(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}}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}}get isEmpty(){return!this.chainHandlers.length}filter(s){const e=this.pipeData;return this.chainHandlers.push((()=>{s(e.payload)&&(e.isAvailable=!0)})),this}switch(){return new l(this)}processChain(s){const e=this.chainHandlers,i=this.pipeData,t=
|
|
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}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)}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)}refine(s){return super.emitByPositive(s)}pushRefiners(s){return super.pushRefiners(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,11 +1,12 @@
|
|
|
1
1
|
import { ICallback, IChainCallback, IErrorCallback, IFilter, IFilterCase, IFilterPayload, IFilterResponse, IFilterSetup, IFilterSwitch } from "./Types";
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class FilterCollection<T> implements IFilter<T>, IFilterSwitch<T> {
|
|
3
3
|
chainHandlers: IChainCallback[];
|
|
4
4
|
pipeData: IFilterPayload;
|
|
5
5
|
response: IFilterResponse;
|
|
6
6
|
private errorHandler;
|
|
7
7
|
get isEmpty(): boolean;
|
|
8
8
|
filter(condition: ICallback<any>): IFilterSetup<T>;
|
|
9
|
+
pushFilters(conditions: ICallback<any>[]): IFilterSetup<T>;
|
|
9
10
|
switch(): FilterSwitchCase<T>;
|
|
10
11
|
processChain(value: T): IFilterResponse;
|
|
11
12
|
addErrorHandler(errorHandler: IErrorCallback): void;
|
|
@@ -13,6 +14,7 @@ export declare class Filter<T> implements IFilter<T>, IFilterSwitch<T> {
|
|
|
13
14
|
export declare class FilterSwitchCase<T> implements IFilterCase<T> {
|
|
14
15
|
private pipe;
|
|
15
16
|
private caseCounter;
|
|
16
|
-
constructor(pipe:
|
|
17
|
+
constructor(pipe: FilterCollection<T>);
|
|
17
18
|
case(condition: ICallback<any>): IFilterCase<T>;
|
|
19
|
+
pushCases(conditions: ICallback<any>[]): IFilterCase<T>;
|
|
18
20
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FilterSwitchCase = exports.
|
|
4
|
-
class
|
|
3
|
+
exports.FilterSwitchCase = exports.FilterCollection = void 0;
|
|
4
|
+
class FilterCollection {
|
|
5
5
|
chainHandlers = [];
|
|
6
6
|
pipeData = { isBreakChain: false, isAvailable: false, payload: null };
|
|
7
7
|
response = { isOK: false, payload: undefined };
|
|
@@ -17,6 +17,13 @@ class Filter {
|
|
|
17
17
|
});
|
|
18
18
|
return this;
|
|
19
19
|
}
|
|
20
|
+
pushFilters(conditions) {
|
|
21
|
+
if (!Array.isArray(conditions))
|
|
22
|
+
return this;
|
|
23
|
+
for (let i = 0; i < conditions.length; i++)
|
|
24
|
+
this.filter(conditions[i]);
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
20
27
|
switch() {
|
|
21
28
|
return new FilterSwitchCase(this);
|
|
22
29
|
}
|
|
@@ -55,7 +62,7 @@ class Filter {
|
|
|
55
62
|
this.errorHandler = errorHandler;
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
|
-
exports.
|
|
65
|
+
exports.FilterCollection = FilterCollection;
|
|
59
66
|
class FilterSwitchCase {
|
|
60
67
|
pipe;
|
|
61
68
|
caseCounter;
|
|
@@ -77,5 +84,12 @@ class FilterSwitchCase {
|
|
|
77
84
|
});
|
|
78
85
|
return this;
|
|
79
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
|
+
}
|
|
80
94
|
}
|
|
81
95
|
exports.FilterSwitchCase = FilterSwitchCase;
|
package/src/outLib/Observable.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Observable = void 0;
|
|
4
4
|
const FunctionLibs_1 = require("./FunctionLibs");
|
|
5
5
|
const SubscribeObject_1 = require("./SubscribeObject");
|
|
6
|
-
const
|
|
6
|
+
const FilterCollection_1 = require("./FilterCollection");
|
|
7
7
|
class Observable {
|
|
8
8
|
value;
|
|
9
9
|
listeners = [];
|
|
@@ -11,7 +11,7 @@ class Observable {
|
|
|
11
11
|
_isDestroyed = false;
|
|
12
12
|
isNextProcess = false;
|
|
13
13
|
listenersForUnsubscribe = [];
|
|
14
|
-
filterCase = new
|
|
14
|
+
filterCase = new FilterCollection_1.FilterCollection();
|
|
15
15
|
constructor(value) {
|
|
16
16
|
this.value = value;
|
|
17
17
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SubscribeObject } from "./SubscribeObject";
|
|
2
|
-
import { ICallback, IErrorCallback, IListener, IOrdered, IOrderedSetup, IOrderedSubscribe, IOrderedSubscriptionLike, ISetObservableValue } from "./Types";
|
|
2
|
+
import { ICallback, IErrorCallback, IListener, IOrdered, IOrderedSetup, IOrderedSubscribe, IOrderedSubscriptionLike, ISetObservableValue, ISetup } 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);
|
|
@@ -11,5 +11,7 @@ export declare class OrderedSubscribeObject<T> extends SubscribeObject<T> implem
|
|
|
11
11
|
unsubscribeByPositive(condition: ICallback<any>): IOrderedSetup<T>;
|
|
12
12
|
emitByNegative(condition: ICallback<any>): IOrderedSetup<T>;
|
|
13
13
|
emitByPositive(condition: ICallback<any>): IOrderedSetup<T>;
|
|
14
|
+
refine(condition: ICallback<any>): ISetup<T>;
|
|
15
|
+
pushRefiners(conditions: ICallback<any>[]): ISetup<T>;
|
|
14
16
|
emitMatch(condition: ICallback<any>): IOrderedSetup<T>;
|
|
15
17
|
}
|
|
@@ -37,6 +37,12 @@ class OrderedSubscribeObject extends SubscribeObject_1.SubscribeObject {
|
|
|
37
37
|
emitByPositive(condition) {
|
|
38
38
|
return super.emitByPositive(condition);
|
|
39
39
|
}
|
|
40
|
+
refine(condition) {
|
|
41
|
+
return super.emitByPositive(condition);
|
|
42
|
+
}
|
|
43
|
+
pushRefiners(conditions) {
|
|
44
|
+
return super.pushRefiners(conditions);
|
|
45
|
+
}
|
|
40
46
|
emitMatch(condition) {
|
|
41
47
|
return super.emitMatch(condition);
|
|
42
48
|
}
|
package/src/outLib/Pipe.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare abstract class Pipe<T> implements ISubscribe<T> {
|
|
|
8
8
|
unsubscribeByPositive(condition: ICallback<T>): ISetup<T>;
|
|
9
9
|
emitByNegative(condition: ICallback<T>): ISetup<T>;
|
|
10
10
|
emitByPositive(condition: ICallback<T>): ISetup<T>;
|
|
11
|
+
refine(condition: ICallback<any>): ISetup<T>;
|
|
12
|
+
pushRefiners(conditions: ICallback<any>[]): ISetup<T>;
|
|
11
13
|
emitMatch(condition: ICallback<T>): ISetup<T>;
|
|
12
14
|
switch(): SwitchCase<T>;
|
|
13
15
|
processChain(listener: IListener<T>): void;
|
|
@@ -18,4 +20,5 @@ export declare class SwitchCase<T> implements ISubscribe<T>, IPipeCase<T> {
|
|
|
18
20
|
constructor(pipe: Pipe<T>);
|
|
19
21
|
subscribe(listener: IListener<T> | ISetObservableValue, errorHandler?: IErrorCallback): ISubscriptionLike | undefined;
|
|
20
22
|
case(condition: ICallback<any>): IPipeCase<T> & ISubscribe<T>;
|
|
23
|
+
pushCases(conditions: ICallback<any>[]): IPipeCase<T> & ISubscribe<T>;
|
|
21
24
|
}
|
package/src/outLib/Pipe.js
CHANGED
|
@@ -46,6 +46,16 @@ class Pipe {
|
|
|
46
46
|
});
|
|
47
47
|
return this;
|
|
48
48
|
}
|
|
49
|
+
refine(condition) {
|
|
50
|
+
return this.emitByPositive(condition);
|
|
51
|
+
}
|
|
52
|
+
pushRefiners(conditions) {
|
|
53
|
+
if (!Array.isArray(conditions))
|
|
54
|
+
return this;
|
|
55
|
+
for (let i = 0; i < conditions.length; i++)
|
|
56
|
+
this.emitByPositive(conditions[i]);
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
49
59
|
emitMatch(condition) {
|
|
50
60
|
const data = this.pipeData;
|
|
51
61
|
this.chainHandlers.push(() => {
|
|
@@ -99,5 +109,12 @@ class SwitchCase {
|
|
|
99
109
|
});
|
|
100
110
|
return this;
|
|
101
111
|
}
|
|
112
|
+
pushCases(conditions) {
|
|
113
|
+
if (!Array.isArray(conditions))
|
|
114
|
+
return this;
|
|
115
|
+
for (let i = 0; i < conditions.length; i++)
|
|
116
|
+
this.case(conditions[i]);
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
102
119
|
}
|
|
103
120
|
exports.SwitchCase = SwitchCase;
|
package/src/outLib/Types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SwitchCase } from "./Pipe";
|
|
2
|
-
import { FilterSwitchCase } from "./
|
|
2
|
+
import { FilterSwitchCase } from "./FilterCollection";
|
|
3
3
|
export type ICallback<T> = (value?: T) => any;
|
|
4
4
|
export type IErrorCallback = (errorData: any, errorMessage: any) => void;
|
|
5
5
|
export type ISubscribe<T> = {
|
|
@@ -83,9 +83,13 @@ export type IOrderedEmitByNegative<T> = {
|
|
|
83
83
|
};
|
|
84
84
|
export type IEmitByPositive<T> = {
|
|
85
85
|
emitByPositive(condition: ICallback<any>): ISetup<T>;
|
|
86
|
+
refine(condition: ICallback<any>): ISetup<T>;
|
|
87
|
+
pushRefiners(conditions: ICallback<any>[]): ISetup<T>;
|
|
86
88
|
};
|
|
87
89
|
export type IOrderedEmitByPositive<T> = {
|
|
88
90
|
emitByPositive(condition: ICallback<any>): IOrderedSetup<T>;
|
|
91
|
+
refine(condition: ICallback<any>): ISetup<T>;
|
|
92
|
+
pushRefiners(conditions: ICallback<any>[]): ISetup<T>;
|
|
89
93
|
};
|
|
90
94
|
export type IEmitMatchCondition<T> = {
|
|
91
95
|
emitMatch(condition: ICallback<any>): ISetup<T>;
|
|
@@ -115,6 +119,7 @@ export type IPipePayload = {
|
|
|
115
119
|
export type IChainCallback = () => void;
|
|
116
120
|
export type IPipeCase<T> = {
|
|
117
121
|
case(condition: ICallback<any>): IPipeCase<T> & ISubscribe<T>;
|
|
122
|
+
pushCases(conditions: ICallback<any>[]): IPipeCase<T> & ISubscribe<T>;
|
|
118
123
|
};
|
|
119
124
|
export type ICombinedSubscriber<T> = IListener<T> | ISetObservableValue;
|
|
120
125
|
export type ISubscribeGroup<T> = ICombinedSubscriber<T> | ICombinedSubscriber<T>[];
|
|
@@ -124,12 +129,14 @@ export type IAddFilter<T> = {
|
|
|
124
129
|
export type IFilterSetup<T> = IFilter<T> & IFilterSwitch<T>;
|
|
125
130
|
export type IFilter<T> = {
|
|
126
131
|
filter(condition: ICallback<any>): IFilterSetup<T>;
|
|
132
|
+
pushFilters(conditions: ICallback<any>[]): IFilterSetup<T>;
|
|
127
133
|
};
|
|
128
134
|
export type IFilterSwitch<T> = {
|
|
129
135
|
switch(): FilterSwitchCase<T>;
|
|
130
136
|
};
|
|
131
137
|
export type IFilterCase<T> = {
|
|
132
138
|
case(condition: ICallback<any>): IFilterCase<T>;
|
|
139
|
+
pushCases(conditions: ICallback<any>[]): IFilterCase<T>;
|
|
133
140
|
};
|
|
134
141
|
export type IFilterPayload = {
|
|
135
142
|
isBreakChain: boolean;
|