evg_observable 2.14.60 → 2.15.0
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/BREAKING_CHANGES.md +70 -0
- package/package.json +12 -6
- package/src/outLib/src/Libraries/Observables/AbstractSwitchCase.d.ts +37 -0
- package/src/outLib/src/Libraries/Observables/AbstractSwitchCase.js +61 -0
- package/src/outLib/src/Libraries/Observables/Collector.d.ts +56 -0
- package/src/outLib/src/Libraries/Observables/Collector.js +86 -0
- package/src/outLib/src/Libraries/Observables/FilterCollection.d.ts +70 -0
- package/src/outLib/src/Libraries/Observables/FilterCollection.js +122 -0
- package/src/outLib/src/Libraries/Observables/FunctionLibs.d.ts +48 -0
- package/src/outLib/src/Libraries/Observables/FunctionLibs.js +101 -0
- package/src/outLib/src/Libraries/Observables/Observable.d.ts +160 -0
- package/src/outLib/src/Libraries/Observables/Observable.js +268 -0
- package/src/outLib/src/Libraries/Observables/OrderedObservable.d.ts +70 -0
- package/src/outLib/src/Libraries/Observables/OrderedObservable.js +106 -0
- package/src/outLib/src/Libraries/Observables/OrderedSubscribeObject.d.ts +53 -0
- package/src/outLib/src/Libraries/Observables/OrderedSubscribeObject.js +72 -0
- package/src/outLib/src/Libraries/Observables/Pipe.d.ts +108 -0
- package/src/outLib/src/Libraries/Observables/Pipe.js +161 -0
- package/src/outLib/src/Libraries/Observables/SubscribeObject.d.ts +83 -0
- package/src/outLib/src/Libraries/Observables/SubscribeObject.js +139 -0
- package/src/outLib/src/Libraries/Observables/Types.d.ts +727 -0
- package/src/outLib/{index.d.ts → src/Libraries/Observables/index.d.ts} +1 -0
- package/repo/evg_observable.js +0 -1
- package/src/outLib/AbstractSwitchCase.d.ts +0 -8
- package/src/outLib/AbstractSwitchCase.js +0 -32
- package/src/outLib/Collector.d.ts +0 -11
- package/src/outLib/Collector.js +0 -39
- package/src/outLib/FilterCollection.d.ts +0 -17
- package/src/outLib/FilterCollection.js +0 -68
- package/src/outLib/FunctionLibs.d.ts +0 -6
- package/src/outLib/FunctionLibs.js +0 -54
- package/src/outLib/Observable.d.ts +0 -29
- package/src/outLib/Observable.js +0 -130
- package/src/outLib/OrderedObservable.d.ts +0 -11
- package/src/outLib/OrderedObservable.js +0 -47
- package/src/outLib/OrderedSubscribeObject.d.ts +0 -10
- package/src/outLib/OrderedSubscribeObject.js +0 -29
- package/src/outLib/Pipe.d.ts +0 -20
- package/src/outLib/Pipe.js +0 -79
- package/src/outLib/SubscribeObject.d.ts +0 -19
- package/src/outLib/SubscribeObject.js +0 -68
- package/src/outLib/Types.d.ts +0 -165
- /package/src/outLib/{Types.js → src/Libraries/Observables/Types.js} +0 -0
- /package/src/outLib/{index.js → src/Libraries/Observables/index.js} +0 -0
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* A class that represents an observable object with subscription, pausing,
|
|
8
|
+
* and piping functionalities. It allows subscribing to updates, handling errors,
|
|
9
|
+
* and processing values through a chain.
|
|
10
|
+
*
|
|
11
|
+
* @template T The type of values handled by SubscribeObject.
|
|
12
|
+
* @extends Pipe<T>
|
|
13
|
+
* @implements ISubscribeObject<T>
|
|
14
|
+
*/
|
|
15
|
+
class SubscribeObject extends Pipe_1.Pipe {
|
|
16
|
+
observer;
|
|
17
|
+
listener;
|
|
18
|
+
/**
|
|
19
|
+
* A callback function used for handling errors in the context of the SubscribeObject.
|
|
20
|
+
* This function logs the provided error data and error message to the console for debugging purposes.
|
|
21
|
+
*
|
|
22
|
+
* @type {IErrorCallback}
|
|
23
|
+
* @param {any} errorData - The data related to the error encountered.
|
|
24
|
+
* @param {any} errorMessage - A descriptive message detailing the error.
|
|
25
|
+
*/
|
|
26
|
+
errorHandler = (errorData, errorMessage) => {
|
|
27
|
+
console.log(`(Unit of SubscribeObject).send(${errorData}) ERROR:`, errorMessage);
|
|
28
|
+
};
|
|
29
|
+
_order = 0;
|
|
30
|
+
paused = false;
|
|
31
|
+
piped = false;
|
|
32
|
+
/**
|
|
33
|
+
* Constructs an instance of the class.
|
|
34
|
+
*
|
|
35
|
+
* @param {IObserver<T>} [observable] - The observer instance to be assigned. Optional parameter.
|
|
36
|
+
* @param {boolean} [isPipe=false] - Determines whether the instance is piped. Defaults to false.
|
|
37
|
+
* @return {void}
|
|
38
|
+
*/
|
|
39
|
+
constructor(observable, isPipe) {
|
|
40
|
+
super();
|
|
41
|
+
this.observer = observable;
|
|
42
|
+
this.piped = !!isPipe;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Subscribes an observer to the current instance and optionally assigns an error handler.
|
|
46
|
+
*
|
|
47
|
+
* @param {ISubscribeGroup<T>} observer - The observer group to subscribe.
|
|
48
|
+
* @param {IErrorCallback} [errorHandler] - Optional callback to handle errors.
|
|
49
|
+
* @return {ISubscriptionLike} An instance representing the subscription.
|
|
50
|
+
*/
|
|
51
|
+
subscribe(observer, errorHandler) {
|
|
52
|
+
this.listener = (0, FunctionLibs_1.getListener)(observer);
|
|
53
|
+
errorHandler && (this.errorHandler = errorHandler);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Unsubscribes the current instance from the associated observer, clears the listener,
|
|
58
|
+
* and resets the internal chain.
|
|
59
|
+
* This method ensures that the instance is properly cleaned up and no longer receives updates.
|
|
60
|
+
*
|
|
61
|
+
* @return {void} Does not return a value.
|
|
62
|
+
*/
|
|
63
|
+
unsubscribe() {
|
|
64
|
+
if (!this.observer)
|
|
65
|
+
return;
|
|
66
|
+
this.observer.unSubscribe(this);
|
|
67
|
+
this.observer = null;
|
|
68
|
+
this.listener = null;
|
|
69
|
+
this.chain.length = 0;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Sends the specified value for processing and updates the flow state.
|
|
73
|
+
*
|
|
74
|
+
* @param {T} value - The value to be sent and processed.
|
|
75
|
+
* @return {void} Does not return a value.
|
|
76
|
+
*/
|
|
77
|
+
send(value) {
|
|
78
|
+
const listener = this.listener;
|
|
79
|
+
if (!listener) {
|
|
80
|
+
this.unsubscribe();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (!this.observer || this.paused)
|
|
84
|
+
return;
|
|
85
|
+
// Fast path (no pipe)
|
|
86
|
+
if (!this.piped) {
|
|
87
|
+
try {
|
|
88
|
+
listener(value);
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
this.errorHandler(value, err);
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
// Slow path (with pipe)
|
|
96
|
+
try {
|
|
97
|
+
this.flow.payload = value;
|
|
98
|
+
this.flow.isBreak = false;
|
|
99
|
+
this.processChain(listener);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
this.errorHandler(value, err);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Resumes the current process or operation from a paused state.
|
|
107
|
+
* Updates the internal state to indicate that it is no longer paused.
|
|
108
|
+
*
|
|
109
|
+
* @return {void} Does not return a value.
|
|
110
|
+
*/
|
|
111
|
+
resume() {
|
|
112
|
+
this.paused = false;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Pauses the current operation or process by setting the paused state to true.
|
|
116
|
+
*
|
|
117
|
+
* @return {void} No value is returned.
|
|
118
|
+
*/
|
|
119
|
+
pause() {
|
|
120
|
+
this.paused = true;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Retrieves the current order value.
|
|
124
|
+
*
|
|
125
|
+
* @return {number} The current value of the order.
|
|
126
|
+
*/
|
|
127
|
+
get order() {
|
|
128
|
+
return this._order;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Sets the order value.
|
|
132
|
+
*
|
|
133
|
+
* @param {number} value - The numerical value to set as the order.
|
|
134
|
+
*/
|
|
135
|
+
set order(value) {
|
|
136
|
+
this._order = value;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.SubscribeObject = SubscribeObject;
|