evg_observable 2.15.0 → 2.15.2
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 +2 -1
- package/src/outLib/AbstractSwitchCase.d.ts +8 -0
- package/src/outLib/AbstractSwitchCase.js +32 -0
- package/src/outLib/Collector.d.ts +11 -0
- package/src/outLib/Collector.js +41 -0
- package/src/outLib/FilterCollection.d.ts +17 -0
- package/src/outLib/FilterCollection.js +69 -0
- package/src/outLib/FunctionLibs.d.ts +6 -0
- package/src/outLib/FunctionLibs.js +53 -0
- package/src/outLib/Observable.d.ts +30 -0
- package/src/outLib/Observable.js +137 -0
- package/src/outLib/OrderedObservable.d.ts +11 -0
- package/src/outLib/OrderedObservable.js +47 -0
- package/src/outLib/OrderedSubscribeObject.d.ts +10 -0
- package/src/outLib/OrderedSubscribeObject.js +29 -0
- package/src/outLib/Pipe.d.ts +20 -0
- package/src/outLib/Pipe.js +80 -0
- package/src/outLib/SubscribeObject.d.ts +18 -0
- package/src/outLib/SubscribeObject.js +72 -0
- package/src/outLib/Types.d.ts +165 -0
- package/src/outLib/src/Libraries/Observables/AbstractSwitchCase.d.ts +0 -37
- package/src/outLib/src/Libraries/Observables/AbstractSwitchCase.js +0 -61
- package/src/outLib/src/Libraries/Observables/Collector.d.ts +0 -56
- package/src/outLib/src/Libraries/Observables/Collector.js +0 -86
- package/src/outLib/src/Libraries/Observables/FilterCollection.d.ts +0 -70
- package/src/outLib/src/Libraries/Observables/FilterCollection.js +0 -122
- package/src/outLib/src/Libraries/Observables/FunctionLibs.d.ts +0 -48
- package/src/outLib/src/Libraries/Observables/FunctionLibs.js +0 -101
- package/src/outLib/src/Libraries/Observables/Observable.d.ts +0 -160
- package/src/outLib/src/Libraries/Observables/Observable.js +0 -268
- package/src/outLib/src/Libraries/Observables/OrderedObservable.d.ts +0 -70
- package/src/outLib/src/Libraries/Observables/OrderedObservable.js +0 -106
- package/src/outLib/src/Libraries/Observables/OrderedSubscribeObject.d.ts +0 -53
- package/src/outLib/src/Libraries/Observables/OrderedSubscribeObject.js +0 -72
- package/src/outLib/src/Libraries/Observables/Pipe.d.ts +0 -108
- package/src/outLib/src/Libraries/Observables/Pipe.js +0 -161
- package/src/outLib/src/Libraries/Observables/SubscribeObject.d.ts +0 -83
- package/src/outLib/src/Libraries/Observables/SubscribeObject.js +0 -139
- package/src/outLib/src/Libraries/Observables/Types.d.ts +0 -727
- /package/src/outLib/{src/Libraries/Observables/Types.js → Types.js} +0 -0
- /package/src/outLib/{src/Libraries/Observables/index.d.ts → index.d.ts} +0 -0
- /package/src/outLib/{src/Libraries/Observables/index.js → index.js} +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SubscribeObject = void 0;
|
|
4
|
+
const Pipe_1 = require("./Pipe");
|
|
5
|
+
const FunctionLibs_1 = require("./FunctionLibs");
|
|
6
|
+
class SubscribeObject extends Pipe_1.Pipe {
|
|
7
|
+
observer;
|
|
8
|
+
listener;
|
|
9
|
+
errorHandler = (errorData, errorMessage) => {
|
|
10
|
+
console.log(`(Unit of SubscribeObject).send(${errorData}) ERROR:`, errorMessage);
|
|
11
|
+
};
|
|
12
|
+
_order = 0;
|
|
13
|
+
paused = false;
|
|
14
|
+
piped = false;
|
|
15
|
+
constructor(observable, isPipe) {
|
|
16
|
+
super();
|
|
17
|
+
this.observer = observable;
|
|
18
|
+
this.piped = !!isPipe;
|
|
19
|
+
}
|
|
20
|
+
subscribe(observer, errorHandler) {
|
|
21
|
+
this.listener = (0, FunctionLibs_1.getListener)(observer);
|
|
22
|
+
errorHandler && (this.errorHandler = errorHandler);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
unsubscribe() {
|
|
26
|
+
if (!this.observer)
|
|
27
|
+
return;
|
|
28
|
+
this.observer.unSubscribe(this);
|
|
29
|
+
this.observer = null;
|
|
30
|
+
this.listener = null;
|
|
31
|
+
this.chain.length = 0;
|
|
32
|
+
}
|
|
33
|
+
send(value) {
|
|
34
|
+
const listener = this.listener;
|
|
35
|
+
if (!listener) {
|
|
36
|
+
this.unsubscribe();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!this.observer || this.paused)
|
|
40
|
+
return;
|
|
41
|
+
if (!this.piped) {
|
|
42
|
+
try {
|
|
43
|
+
listener(value);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
this.errorHandler(value, err);
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
this.flow.payload = value;
|
|
52
|
+
this.flow.isBreak = false;
|
|
53
|
+
this.processChain(listener);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
this.errorHandler(value, err);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
resume() {
|
|
60
|
+
this.paused = false;
|
|
61
|
+
}
|
|
62
|
+
pause() {
|
|
63
|
+
this.paused = true;
|
|
64
|
+
}
|
|
65
|
+
get order() {
|
|
66
|
+
return this._order;
|
|
67
|
+
}
|
|
68
|
+
set order(value) {
|
|
69
|
+
this._order = value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.SubscribeObject = SubscribeObject;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { PipeSwitchCase } from "./Pipe";
|
|
2
|
+
import { FilterSwitchCase } from "./FilterCollection";
|
|
3
|
+
export type ICallback<T> = (value?: T) => any;
|
|
4
|
+
export type IErrorCallback = (errorData: any, errorMessage: any) => void;
|
|
5
|
+
export type ISubscribe<T> = {
|
|
6
|
+
subscribe(listener: ISubscribeGroup<T>, errorHandler?: IErrorCallback): ISubscriptionLike | undefined;
|
|
7
|
+
};
|
|
8
|
+
export type IListener<T> = ICallback<T>;
|
|
9
|
+
export type IDestroy = {
|
|
10
|
+
destroy(): void;
|
|
11
|
+
isDestroyed: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type IOrder = {
|
|
14
|
+
order: number;
|
|
15
|
+
};
|
|
16
|
+
export type ISwitch<T> = {
|
|
17
|
+
switch(): PipeSwitchCase<T>;
|
|
18
|
+
};
|
|
19
|
+
export type IOrderedSwitch<T> = {
|
|
20
|
+
switch(): PipeSwitchCase<T>;
|
|
21
|
+
};
|
|
22
|
+
export type IOnce<T> = {
|
|
23
|
+
setOnce(): ISubscribe<T>;
|
|
24
|
+
};
|
|
25
|
+
export type IOrderedOnce<T> = {
|
|
26
|
+
setOnce(): IOrderedSubscribe<T>;
|
|
27
|
+
};
|
|
28
|
+
export type ISetObservableValue = {
|
|
29
|
+
next(value: any): void;
|
|
30
|
+
};
|
|
31
|
+
export type ISubscriptionLike = {
|
|
32
|
+
unsubscribe(): void;
|
|
33
|
+
};
|
|
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
|
+
export type ISubscribeObject<T> = ISubscriptionLike & IPause & IOrder & ISend<T> & ISetup<T>;
|
|
37
|
+
export type ISubscribeCounter = {
|
|
38
|
+
size(): number;
|
|
39
|
+
};
|
|
40
|
+
export type ISubscriber<T> = {
|
|
41
|
+
getValue(): T | undefined;
|
|
42
|
+
isEnable: boolean;
|
|
43
|
+
} & ISubscribe<T>;
|
|
44
|
+
export type IObserver<T> = ISetObservableValue & ISubscriber<T> & IDestroy & ISubscribeCounter & IObservablePipe<T> & {
|
|
45
|
+
unSubscribe(subscriber: ISubscriptionLike): void;
|
|
46
|
+
unsubscribeAll(): void;
|
|
47
|
+
disable(): void;
|
|
48
|
+
enable(): void;
|
|
49
|
+
};
|
|
50
|
+
export type IStream<T> = {
|
|
51
|
+
stream(value: T[]): void;
|
|
52
|
+
};
|
|
53
|
+
export type IPause = {
|
|
54
|
+
pause(): void;
|
|
55
|
+
resume(): void;
|
|
56
|
+
};
|
|
57
|
+
export type IObservablePipe<T> = {
|
|
58
|
+
pipe(): ISetup<T> | undefined;
|
|
59
|
+
};
|
|
60
|
+
export type IOrderedObservablePipe<T> = {
|
|
61
|
+
pipe(): ISetup<T> | undefined;
|
|
62
|
+
};
|
|
63
|
+
export type ISend<T> = {
|
|
64
|
+
send(value: T): void;
|
|
65
|
+
};
|
|
66
|
+
export type IUnsubscribeByNegative<T> = {
|
|
67
|
+
unsubscribeByNegative(condition: ICallback<T>): ISetup<T>;
|
|
68
|
+
};
|
|
69
|
+
export type IOrderedUnsubscribeByNegative<T> = {
|
|
70
|
+
unsubscribeByNegative(condition: ICallback<T>): IOrderedSetup<T>;
|
|
71
|
+
};
|
|
72
|
+
export type IUnsubscribeByPositive<T> = {
|
|
73
|
+
unsubscribeBy(condition: ICallback<T>): ISetup<T>;
|
|
74
|
+
};
|
|
75
|
+
export type IOrderedUnsubscribeByPositive<T> = {
|
|
76
|
+
unsubscribeBy(condition: ICallback<T>): ISetup<T>;
|
|
77
|
+
};
|
|
78
|
+
export type IEmitByNegative<T> = {
|
|
79
|
+
emitByNegative(condition: ICallback<T>): ISetup<T>;
|
|
80
|
+
};
|
|
81
|
+
export type IOrderedEmitByNegative<T> = {
|
|
82
|
+
emitByNegative(condition: ICallback<T>): IOrderedSetup<T>;
|
|
83
|
+
};
|
|
84
|
+
export type IEmitByPositive<T> = {
|
|
85
|
+
refine(condition: ICallback<T>): ISetup<T>;
|
|
86
|
+
pushRefiners(conditions: ICallback<T>[]): ISetup<T>;
|
|
87
|
+
};
|
|
88
|
+
export type ITransform<T> = {
|
|
89
|
+
then<K>(condition: ICallback<T>): ISetup<K>;
|
|
90
|
+
};
|
|
91
|
+
export type ISerialisation = {
|
|
92
|
+
serialize(): ISetup<string>;
|
|
93
|
+
deserialize<K>(): ISetup<K>;
|
|
94
|
+
};
|
|
95
|
+
export type IOrderedEmitByPositive<T> = {
|
|
96
|
+
refine(condition: ICallback<any>): ISetup<T>;
|
|
97
|
+
pushRefiners(conditions: ICallback<any>[]): ISetup<T>;
|
|
98
|
+
};
|
|
99
|
+
export type IOrderedTransform<T> = {
|
|
100
|
+
then<K>(condition: ICallback<T>): ISetup<K>;
|
|
101
|
+
};
|
|
102
|
+
export type IOrderedSerialisation = {
|
|
103
|
+
serialize(): ISetup<string>;
|
|
104
|
+
deserialize<K>(): ISetup<K>;
|
|
105
|
+
};
|
|
106
|
+
export type IEmitMatchCondition<T> = {
|
|
107
|
+
emitMatch(condition: ICallback<any>): ISetup<T>;
|
|
108
|
+
};
|
|
109
|
+
export type IOrderedEmitMatchCondition<T> = {
|
|
110
|
+
emitMatch(condition: ICallback<any>): IOrderedSetup<T>;
|
|
111
|
+
};
|
|
112
|
+
export type ICollector = IDestroy & ISubscribeCounter & {
|
|
113
|
+
collect(...subscriptionLikeList: ISubscriptionLike[]): void;
|
|
114
|
+
unsubscribe(subscriptionLike: ISubscriptionLike): void;
|
|
115
|
+
unsubscribeAll(): void;
|
|
116
|
+
};
|
|
117
|
+
export type IOrderedObservable = {
|
|
118
|
+
sortByOrder(): boolean;
|
|
119
|
+
};
|
|
120
|
+
export type IOrdered<T> = IObserver<T> & IOrderedObservable & IOrderedObservablePipe<T>;
|
|
121
|
+
export type IOrderedSubscriptionLike = (ISubscriptionLike & IOrder);
|
|
122
|
+
export type IOrderedSubscribe<T> = {
|
|
123
|
+
subscribe(listener: IListener<T>, errorHandler?: IErrorCallback): IOrderedSubscriptionLike;
|
|
124
|
+
};
|
|
125
|
+
export type IChainContainer = {
|
|
126
|
+
chain: any[];
|
|
127
|
+
};
|
|
128
|
+
export type IPipePayload = {
|
|
129
|
+
isBreak: boolean;
|
|
130
|
+
isUnsubscribe: boolean;
|
|
131
|
+
isAvailable: boolean;
|
|
132
|
+
payload: any;
|
|
133
|
+
};
|
|
134
|
+
export type IChainCallback = (data: IPipePayload) => void;
|
|
135
|
+
export type IPipeCase<T> = ISubscribe<T> & {
|
|
136
|
+
case(condition: ICallback<any>): IPipeCase<T> & ISubscribe<T>;
|
|
137
|
+
pushCases(conditions: ICallback<any>[]): IPipeCase<T> & ISubscribe<T>;
|
|
138
|
+
};
|
|
139
|
+
export type ICombinedSubscriber<T> = IListener<T> | ISetObservableValue;
|
|
140
|
+
export type ISubscribeGroup<T> = ICombinedSubscriber<T> | ICombinedSubscriber<T>[];
|
|
141
|
+
export type IAddFilter<T> = {
|
|
142
|
+
addFilter(): IFilterSetup<T>;
|
|
143
|
+
};
|
|
144
|
+
export type IFilterSetup<T> = IFilter<T> & IFilterSwitch<T>;
|
|
145
|
+
export type IFilter<T> = {
|
|
146
|
+
filter(condition: ICallback<any>): IFilterSetup<T>;
|
|
147
|
+
pushFilters(conditions: ICallback<any>[]): IFilterSetup<T>;
|
|
148
|
+
};
|
|
149
|
+
export type IFilterSwitch<T> = {
|
|
150
|
+
switch(): FilterSwitchCase<T>;
|
|
151
|
+
};
|
|
152
|
+
export type IFilterCase<T> = {
|
|
153
|
+
case(condition: ICallback<any>): IFilterCase<T>;
|
|
154
|
+
pushCases(conditions: ICallback<any>[]): IFilterCase<T>;
|
|
155
|
+
};
|
|
156
|
+
export type IFilterPayload = {
|
|
157
|
+
isBreak: boolean;
|
|
158
|
+
isAvailable: boolean;
|
|
159
|
+
payload: any;
|
|
160
|
+
};
|
|
161
|
+
export type IFilterChainCallback = (data: IFilterPayload) => void;
|
|
162
|
+
export type IFilterResponse = {
|
|
163
|
+
isOK: boolean;
|
|
164
|
+
payload: any;
|
|
165
|
+
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { ICallback, IChainContainer } from "./Types";
|
|
2
|
-
/**
|
|
3
|
-
* Abstract class representing a Switch-Case control structure for handling
|
|
4
|
-
* conditional chains of operations.
|
|
5
|
-
*
|
|
6
|
-
* @template T - The type of the input payload expected by the conditions.
|
|
7
|
-
* @template P - The type extending IChainContainer, representing the container for the chain of operations.
|
|
8
|
-
* @template W - The type of the subclass or the expected return type for method chaining.
|
|
9
|
-
*/
|
|
10
|
-
export declare abstract class SwitchCase<T, P extends IChainContainer, W> {
|
|
11
|
-
protected pipe: P;
|
|
12
|
-
protected counter: number;
|
|
13
|
-
/**
|
|
14
|
-
* Creates an instance of the class and initializes the pipe and counter.
|
|
15
|
-
*
|
|
16
|
-
* @param {P} pipe - The pipe object used for initialization.
|
|
17
|
-
* @return {void}
|
|
18
|
-
*/
|
|
19
|
-
constructor(pipe: P);
|
|
20
|
-
/**
|
|
21
|
-
* Adds a conditional case to the processing chain. The case determines
|
|
22
|
-
* whether further processing should continue based on the provided condition.
|
|
23
|
-
*
|
|
24
|
-
* @param {ICallback<any>} condition - A callback function that takes a payload
|
|
25
|
-
* and evaluates a condition. If the condition is met, further processing may be stopped.
|
|
26
|
-
* @return {W} Returns the current instance for method chaining.
|
|
27
|
-
*/
|
|
28
|
-
case(condition: ICallback<any>): W;
|
|
29
|
-
/**
|
|
30
|
-
* Adds an array of conditions to the current instance by iterating through the provided array
|
|
31
|
-
* and adding each individual condition using the `case` method of the instance.
|
|
32
|
-
*
|
|
33
|
-
* @param {ICallback<any>[]} conditions - An array of callback functions representing conditions to be added.
|
|
34
|
-
* @return {W} The current instance after all conditions have been added.
|
|
35
|
-
*/
|
|
36
|
-
pushCases(conditions: ICallback<any>[]): W;
|
|
37
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SwitchCase = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Abstract class representing a Switch-Case control structure for handling
|
|
6
|
-
* conditional chains of operations.
|
|
7
|
-
*
|
|
8
|
-
* @template T - The type of the input payload expected by the conditions.
|
|
9
|
-
* @template P - The type extending IChainContainer, representing the container for the chain of operations.
|
|
10
|
-
* @template W - The type of the subclass or the expected return type for method chaining.
|
|
11
|
-
*/
|
|
12
|
-
class SwitchCase {
|
|
13
|
-
pipe;
|
|
14
|
-
counter;
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the class and initializes the pipe and counter.
|
|
17
|
-
*
|
|
18
|
-
* @param {P} pipe - The pipe object used for initialization.
|
|
19
|
-
* @return {void}
|
|
20
|
-
*/
|
|
21
|
-
constructor(pipe) {
|
|
22
|
-
this.pipe = pipe;
|
|
23
|
-
this.counter = pipe.chain.length ? pipe.chain.length : 0;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Adds a conditional case to the processing chain. The case determines
|
|
27
|
-
* whether further processing should continue based on the provided condition.
|
|
28
|
-
*
|
|
29
|
-
* @param {ICallback<any>} condition - A callback function that takes a payload
|
|
30
|
-
* and evaluates a condition. If the condition is met, further processing may be stopped.
|
|
31
|
-
* @return {W} Returns the current instance for method chaining.
|
|
32
|
-
*/
|
|
33
|
-
case(condition) {
|
|
34
|
-
this.counter++;
|
|
35
|
-
const id = this.counter;
|
|
36
|
-
const chain = this.pipe.chain;
|
|
37
|
-
chain.push((data) => {
|
|
38
|
-
data.isAvailable = true;
|
|
39
|
-
if (condition(data.payload))
|
|
40
|
-
data.isBreak = true;
|
|
41
|
-
if (id === chain.length && !data.isBreak)
|
|
42
|
-
data.isAvailable = false;
|
|
43
|
-
});
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Adds an array of conditions to the current instance by iterating through the provided array
|
|
48
|
-
* and adding each individual condition using the `case` method of the instance.
|
|
49
|
-
*
|
|
50
|
-
* @param {ICallback<any>[]} conditions - An array of callback functions representing conditions to be added.
|
|
51
|
-
* @return {W} The current instance after all conditions have been added.
|
|
52
|
-
*/
|
|
53
|
-
pushCases(conditions) {
|
|
54
|
-
if (!Array.isArray(conditions))
|
|
55
|
-
return this;
|
|
56
|
-
for (let i = 0; i < conditions.length; i++)
|
|
57
|
-
this.case(conditions[i]);
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.SwitchCase = SwitchCase;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { ICollector, ISubscriptionLike } from "./Types";
|
|
2
|
-
/**
|
|
3
|
-
* The Collector class is responsible for managing a collection of resources or subscription-like objects
|
|
4
|
-
* that need to be cleaned up or unsubscribed from, ensuring proper resource management.
|
|
5
|
-
* Implements the ICollector interface.
|
|
6
|
-
*
|
|
7
|
-
* The typical lifecycle of a Collector involves collecting subscription-like items, optionally
|
|
8
|
-
* unsubscribing from specific ones, unsubscribing from all resources, and destroying the collector
|
|
9
|
-
* when it's no longer needed.
|
|
10
|
-
*/
|
|
11
|
-
export declare class Collector implements ICollector {
|
|
12
|
-
protected arr: ISubscriptionLike[];
|
|
13
|
-
private killed;
|
|
14
|
-
/**
|
|
15
|
-
* Adds one or more subscription-like objects to the internal collection.
|
|
16
|
-
* Ensures the subscriptions are saved for future management if the object
|
|
17
|
-
* is not in a "killed" state.
|
|
18
|
-
*
|
|
19
|
-
* @param {ISubscriptionLike[]} subscriptionLikeList - The subscription-like objects to be collected.
|
|
20
|
-
* @return {void} This method does not return a value.
|
|
21
|
-
*/
|
|
22
|
-
collect(...subscriptionLikeList: ISubscriptionLike[]): void;
|
|
23
|
-
/**
|
|
24
|
-
* Unsubscribes a given subscription and removes it from the internal array.
|
|
25
|
-
*
|
|
26
|
-
* @param {ISubscriptionLike | undefined} subscriptionLike - The subscription to unsubscribe and remove. If undefined, no action is taken.
|
|
27
|
-
* @return {void} This method does not return a value.
|
|
28
|
-
*/
|
|
29
|
-
unsubscribe(subscriptionLike: ISubscriptionLike | undefined): void;
|
|
30
|
-
/**
|
|
31
|
-
* Unsubscribes from all the currently active subscriptions managed by this instance.
|
|
32
|
-
* If the instance is marked as killed, the method will exit without performing any action.
|
|
33
|
-
*
|
|
34
|
-
* @return {void | null} Returns `null` if the instance is killed, otherwise does not return a value.
|
|
35
|
-
*/
|
|
36
|
-
unsubscribeAll(): void | null;
|
|
37
|
-
/**
|
|
38
|
-
* Determines the size of the array managed by the instance.
|
|
39
|
-
* If the instance is marked as killed, the size is returned as 0.
|
|
40
|
-
*
|
|
41
|
-
* @return {number} The number of elements in the array, or 0 if the instance is killed.
|
|
42
|
-
*/
|
|
43
|
-
size(): number;
|
|
44
|
-
/**
|
|
45
|
-
* Cleans up resources by unsubscribing from all subscriptions, clearing the array, and marking the instance as destroyed.
|
|
46
|
-
*
|
|
47
|
-
* @return {void} Does not return any value.
|
|
48
|
-
*/
|
|
49
|
-
destroy(): void;
|
|
50
|
-
/**
|
|
51
|
-
* Checks if the object is destroyed.
|
|
52
|
-
*
|
|
53
|
-
* @return {boolean} Returns true if the object is destroyed, otherwise false.
|
|
54
|
-
*/
|
|
55
|
-
get isDestroyed(): boolean;
|
|
56
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Collector = void 0;
|
|
4
|
-
const FunctionLibs_1 = require("./FunctionLibs");
|
|
5
|
-
/**
|
|
6
|
-
* The Collector class is responsible for managing a collection of resources or subscription-like objects
|
|
7
|
-
* that need to be cleaned up or unsubscribed from, ensuring proper resource management.
|
|
8
|
-
* Implements the ICollector interface.
|
|
9
|
-
*
|
|
10
|
-
* The typical lifecycle of a Collector involves collecting subscription-like items, optionally
|
|
11
|
-
* unsubscribing from specific ones, unsubscribing from all resources, and destroying the collector
|
|
12
|
-
* when it's no longer needed.
|
|
13
|
-
*/
|
|
14
|
-
class Collector {
|
|
15
|
-
arr = [];
|
|
16
|
-
killed = false;
|
|
17
|
-
/**
|
|
18
|
-
* Adds one or more subscription-like objects to the internal collection.
|
|
19
|
-
* Ensures the subscriptions are saved for future management if the object
|
|
20
|
-
* is not in a "killed" state.
|
|
21
|
-
*
|
|
22
|
-
* @param {ISubscriptionLike[]} subscriptionLikeList - The subscription-like objects to be collected.
|
|
23
|
-
* @return {void} This method does not return a value.
|
|
24
|
-
*/
|
|
25
|
-
collect(...subscriptionLikeList) {
|
|
26
|
-
if (!this.killed)
|
|
27
|
-
this.arr.push(...subscriptionLikeList);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Unsubscribes a given subscription and removes it from the internal array.
|
|
31
|
-
*
|
|
32
|
-
* @param {ISubscriptionLike | undefined} subscriptionLike - The subscription to unsubscribe and remove. If undefined, no action is taken.
|
|
33
|
-
* @return {void} This method does not return a value.
|
|
34
|
-
*/
|
|
35
|
-
unsubscribe(subscriptionLike) {
|
|
36
|
-
if (this.killed)
|
|
37
|
-
return;
|
|
38
|
-
subscriptionLike?.unsubscribe();
|
|
39
|
-
(0, FunctionLibs_1.quickDeleteFromArray)(this.arr, subscriptionLike);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Unsubscribes from all the currently active subscriptions managed by this instance.
|
|
43
|
-
* If the instance is marked as killed, the method will exit without performing any action.
|
|
44
|
-
*
|
|
45
|
-
* @return {void | null} Returns `null` if the instance is killed, otherwise does not return a value.
|
|
46
|
-
*/
|
|
47
|
-
unsubscribeAll() {
|
|
48
|
-
if (this.killed)
|
|
49
|
-
return;
|
|
50
|
-
const arr = this.arr;
|
|
51
|
-
for (let i = 0; i < arr.length; i++)
|
|
52
|
-
arr[i].unsubscribe();
|
|
53
|
-
arr.length = 0;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Determines the size of the array managed by the instance.
|
|
57
|
-
* If the instance is marked as killed, the size is returned as 0.
|
|
58
|
-
*
|
|
59
|
-
* @return {number} The number of elements in the array, or 0 if the instance is killed.
|
|
60
|
-
*/
|
|
61
|
-
size() {
|
|
62
|
-
if (this.killed)
|
|
63
|
-
return 0;
|
|
64
|
-
return this.arr.length;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Cleans up resources by unsubscribing from all subscriptions, clearing the array, and marking the instance as destroyed.
|
|
68
|
-
*
|
|
69
|
-
* @return {void} Does not return any value.
|
|
70
|
-
*/
|
|
71
|
-
destroy() {
|
|
72
|
-
this.unsubscribeAll();
|
|
73
|
-
this.arr.length = 0;
|
|
74
|
-
this.arr = 0;
|
|
75
|
-
this.killed = true;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Checks if the object is destroyed.
|
|
79
|
-
*
|
|
80
|
-
* @return {boolean} Returns true if the object is destroyed, otherwise false.
|
|
81
|
-
*/
|
|
82
|
-
get isDestroyed() {
|
|
83
|
-
return this.killed;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.Collector = Collector;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { ICallback, IErrorCallback, IFilter, IFilterCase, IFilterChainCallback, IFilterPayload, IFilterResponse, IFilterSetup, IFilterSwitch } from "./Types";
|
|
2
|
-
import { SwitchCase } from "./AbstractSwitchCase";
|
|
3
|
-
/**
|
|
4
|
-
* FilterCollection is a generic class implementing the IFilter and IFilterSwitch interfaces.
|
|
5
|
-
* It is designed to handle a series of filtering operations on a given payload, structured as a chain of filter methods.
|
|
6
|
-
* The class allows addition of filters, chaining of multiple filters, and provides mechanisms for handling payload processing flow.
|
|
7
|
-
*
|
|
8
|
-
* @template T The type of data that the filters will operate upon.
|
|
9
|
-
*/
|
|
10
|
-
export declare class FilterCollection<T> implements IFilter<T>, IFilterSwitch<T> {
|
|
11
|
-
chain: IFilterChainCallback[];
|
|
12
|
-
flow: IFilterPayload;
|
|
13
|
-
response: IFilterResponse;
|
|
14
|
-
private errHandler;
|
|
15
|
-
/**
|
|
16
|
-
* Determines whether the chain is empty.
|
|
17
|
-
* @return {boolean} Returns true if the chain contains no elements, otherwise false.
|
|
18
|
-
*/
|
|
19
|
-
get isEmpty(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Adds a callback to the filter chain and returns the current instance.
|
|
22
|
-
*
|
|
23
|
-
* @param {IFilterChainCallback} callback - The callback function to be added to the filter chain.
|
|
24
|
-
* @return {IFilterSetup<T>} The current instance of IFilterSetup.
|
|
25
|
-
*/
|
|
26
|
-
private push;
|
|
27
|
-
/**
|
|
28
|
-
* Filters the data based on the given condition.
|
|
29
|
-
*
|
|
30
|
-
* @param {ICallback<any>} condition - A callback function that determines whether a data item should be included.
|
|
31
|
-
* Should return a truthy value to include the item.
|
|
32
|
-
* @return {IFilterSetup<T>} - The updated filter setup after applying the condition.
|
|
33
|
-
*/
|
|
34
|
-
filter(condition: ICallback<any>): IFilterSetup<T>;
|
|
35
|
-
/**
|
|
36
|
-
* Adds an array of filter conditions to the current filter setup.
|
|
37
|
-
*
|
|
38
|
-
* @param {ICallback<any>[]} conditions - An array of callback functions representing filter conditions.
|
|
39
|
-
* @return {IFilterSetup<T>} The updated filter setup instance.
|
|
40
|
-
*/
|
|
41
|
-
pushFilters(conditions: ICallback<any>[]): IFilterSetup<T>;
|
|
42
|
-
/**
|
|
43
|
-
* Creates and returns a new instance of the `FilterSwitchCase` class to handle switch case logic with the current context.
|
|
44
|
-
*
|
|
45
|
-
* @return {FilterSwitchCase<T>} A new instance of `FilterSwitchCase` initialized with the current context.
|
|
46
|
-
*/
|
|
47
|
-
switch(): FilterSwitchCase<T>;
|
|
48
|
-
/**
|
|
49
|
-
* Processes a chain of functions with the given input value and manages the execution flow through the chain.
|
|
50
|
-
*
|
|
51
|
-
* @param {T} value - The input value to be processed through the chain.
|
|
52
|
-
* @return {IFilterResponse} The final response containing the processing status and payload.
|
|
53
|
-
*/
|
|
54
|
-
processChain(value: T): IFilterResponse;
|
|
55
|
-
/**
|
|
56
|
-
* Assigns an error handler function to manage errors within the application.
|
|
57
|
-
*
|
|
58
|
-
* @param {IErrorCallback} errorHandler - A callback function that will handle error events.
|
|
59
|
-
* @return {void}
|
|
60
|
-
*/
|
|
61
|
-
addErrorHandler(errorHandler: IErrorCallback): void;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* The FilterSwitchCase class extends the SwitchCase class and represents a specific type of switch case
|
|
65
|
-
* logic applied to a collection of filters. It is used for branching logic based on filter cases.
|
|
66
|
-
*
|
|
67
|
-
* @template T - The type of the elements being processed by the filters.
|
|
68
|
-
*/
|
|
69
|
-
export declare class FilterSwitchCase<T> extends SwitchCase<T, FilterCollection<T>, IFilterCase<T>> {
|
|
70
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FilterSwitchCase = exports.FilterCollection = void 0;
|
|
4
|
-
const AbstractSwitchCase_1 = require("./AbstractSwitchCase");
|
|
5
|
-
/**
|
|
6
|
-
* FilterCollection is a generic class implementing the IFilter and IFilterSwitch interfaces.
|
|
7
|
-
* It is designed to handle a series of filtering operations on a given payload, structured as a chain of filter methods.
|
|
8
|
-
* The class allows addition of filters, chaining of multiple filters, and provides mechanisms for handling payload processing flow.
|
|
9
|
-
*
|
|
10
|
-
* @template T The type of data that the filters will operate upon.
|
|
11
|
-
*/
|
|
12
|
-
class FilterCollection {
|
|
13
|
-
chain = [];
|
|
14
|
-
flow = { isBreak: false, isAvailable: false, payload: null };
|
|
15
|
-
response = { isOK: false, payload: undefined };
|
|
16
|
-
errHandler;
|
|
17
|
-
/**
|
|
18
|
-
* Determines whether the chain is empty.
|
|
19
|
-
* @return {boolean} Returns true if the chain contains no elements, otherwise false.
|
|
20
|
-
*/
|
|
21
|
-
get isEmpty() {
|
|
22
|
-
return !this.chain.length;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Adds a callback to the filter chain and returns the current instance.
|
|
26
|
-
*
|
|
27
|
-
* @param {IFilterChainCallback} callback - The callback function to be added to the filter chain.
|
|
28
|
-
* @return {IFilterSetup<T>} The current instance of IFilterSetup.
|
|
29
|
-
*/
|
|
30
|
-
push(callback) {
|
|
31
|
-
this.chain.push(callback);
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Filters the data based on the given condition.
|
|
36
|
-
*
|
|
37
|
-
* @param {ICallback<any>} condition - A callback function that determines whether a data item should be included.
|
|
38
|
-
* Should return a truthy value to include the item.
|
|
39
|
-
* @return {IFilterSetup<T>} - The updated filter setup after applying the condition.
|
|
40
|
-
*/
|
|
41
|
-
filter(condition) {
|
|
42
|
-
return this.push((data) => condition(data.payload) && (data.isAvailable = true));
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Adds an array of filter conditions to the current filter setup.
|
|
46
|
-
*
|
|
47
|
-
* @param {ICallback<any>[]} conditions - An array of callback functions representing filter conditions.
|
|
48
|
-
* @return {IFilterSetup<T>} The updated filter setup instance.
|
|
49
|
-
*/
|
|
50
|
-
pushFilters(conditions) {
|
|
51
|
-
if (!Array.isArray(conditions))
|
|
52
|
-
return this;
|
|
53
|
-
for (let i = 0; i < conditions.length; i++)
|
|
54
|
-
this.filter(conditions[i]);
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Creates and returns a new instance of the `FilterSwitchCase` class to handle switch case logic with the current context.
|
|
59
|
-
*
|
|
60
|
-
* @return {FilterSwitchCase<T>} A new instance of `FilterSwitchCase` initialized with the current context.
|
|
61
|
-
*/
|
|
62
|
-
switch() {
|
|
63
|
-
return new FilterSwitchCase(this);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Processes a chain of functions with the given input value and manages the execution flow through the chain.
|
|
67
|
-
*
|
|
68
|
-
* @param {T} value - The input value to be processed through the chain.
|
|
69
|
-
* @return {IFilterResponse} The final response containing the processing status and payload.
|
|
70
|
-
*/
|
|
71
|
-
processChain(value) {
|
|
72
|
-
const chain = this.chain;
|
|
73
|
-
const data = this.flow;
|
|
74
|
-
const response = this.response;
|
|
75
|
-
response.isOK = false;
|
|
76
|
-
response.payload = undefined;
|
|
77
|
-
data.payload = value;
|
|
78
|
-
data.isBreak = false;
|
|
79
|
-
try {
|
|
80
|
-
const len = chain.length;
|
|
81
|
-
for (let i = 0; i < len; i++) {
|
|
82
|
-
data.isAvailable = false;
|
|
83
|
-
chain[i](data);
|
|
84
|
-
if (!data.isAvailable)
|
|
85
|
-
return response;
|
|
86
|
-
if (data.isBreak)
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
if (this.errHandler) {
|
|
92
|
-
this.errHandler(err, "Filter.processChain ERROR:");
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
console.log("Filter.processChain ERROR:", err);
|
|
96
|
-
}
|
|
97
|
-
return response;
|
|
98
|
-
}
|
|
99
|
-
response.isOK = true;
|
|
100
|
-
response.payload = data.payload;
|
|
101
|
-
return response;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Assigns an error handler function to manage errors within the application.
|
|
105
|
-
*
|
|
106
|
-
* @param {IErrorCallback} errorHandler - A callback function that will handle error events.
|
|
107
|
-
* @return {void}
|
|
108
|
-
*/
|
|
109
|
-
addErrorHandler(errorHandler) {
|
|
110
|
-
this.errHandler = errorHandler;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.FilterCollection = FilterCollection;
|
|
114
|
-
/**
|
|
115
|
-
* The FilterSwitchCase class extends the SwitchCase class and represents a specific type of switch case
|
|
116
|
-
* logic applied to a collection of filters. It is used for branching logic based on filter cases.
|
|
117
|
-
*
|
|
118
|
-
* @template T - The type of the elements being processed by the filters.
|
|
119
|
-
*/
|
|
120
|
-
class FilterSwitchCase extends AbstractSwitchCase_1.SwitchCase {
|
|
121
|
-
}
|
|
122
|
-
exports.FilterSwitchCase = FilterSwitchCase;
|