evg_observable 2.14.61 → 2.15.1

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.
@@ -3,25 +3,63 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SubscribeObject = void 0;
4
4
  const Pipe_1 = require("./Pipe");
5
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
+ */
6
15
  class SubscribeObject extends Pipe_1.Pipe {
7
16
  observer;
8
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
+ */
9
26
  errorHandler = (errorData, errorMessage) => {
10
27
  console.log(`(Unit of SubscribeObject).send(${errorData}) ERROR:`, errorMessage);
11
28
  };
12
29
  _order = 0;
13
30
  paused = false;
14
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
+ */
15
39
  constructor(observable, isPipe) {
16
40
  super();
17
41
  this.observer = observable;
18
42
  this.piped = !!isPipe;
19
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
+ */
20
51
  subscribe(observer, errorHandler) {
21
52
  this.listener = (0, FunctionLibs_1.getListener)(observer);
22
53
  errorHandler && (this.errorHandler = errorHandler);
23
54
  return this;
24
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
+ */
25
63
  unsubscribe() {
26
64
  if (!this.observer)
27
65
  return;
@@ -30,39 +68,72 @@ class SubscribeObject extends Pipe_1.Pipe {
30
68
  this.listener = null;
31
69
  this.chain.length = 0;
32
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
+ */
33
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)
34
96
  try {
35
97
  this.flow.payload = value;
36
98
  this.flow.isBreak = false;
37
- this.processValue(value);
99
+ this.processChain(listener);
38
100
  }
39
101
  catch (err) {
40
102
  this.errorHandler(value, err);
41
103
  }
42
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
+ */
43
111
  resume() {
44
112
  this.paused = false;
45
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
+ */
46
119
  pause() {
47
120
  this.paused = true;
48
121
  }
122
+ /**
123
+ * Retrieves the current order value.
124
+ *
125
+ * @return {number} The current value of the order.
126
+ */
49
127
  get order() {
50
128
  return this._order;
51
129
  }
130
+ /**
131
+ * Sets the order value.
132
+ *
133
+ * @param {number} value - The numerical value to set as the order.
134
+ */
52
135
  set order(value) {
53
136
  this._order = value;
54
137
  }
55
- processValue(value) {
56
- const listener = this.listener;
57
- if (!listener)
58
- return this.unsubscribe();
59
- if (!this.observer)
60
- return;
61
- if (this.paused)
62
- return;
63
- if (!this.piped)
64
- return listener(value);
65
- return this.processChain(listener);
66
- }
67
138
  }
68
139
  exports.SubscribeObject = SubscribeObject;