evg_observable 1.5.39 → 1.5.41

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
@@ -8,7 +8,7 @@ EVG Observable - is a light library for simple use.
8
8
 
9
9
  ## What is EVG Observable?
10
10
 
11
- EVG Observable is a compact, lightweight library designed for handling asynchronous events. Despite its small size, it offers over 20 powerful techniques for event management. Despite this, it provides over 20 different ways of event handling.
11
+ EVG Observable is a compact, lightweight library designed for handling asynchronous events. Despite its small size, it offers over 20 powerful techniques for event management.
12
12
 
13
13
  ## Installation
14
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evg_observable",
3
- "version": "1.5.39",
3
+ "version": "1.5.41",
4
4
  "description": "Alternative fast and light library version - observable.",
5
5
  "directories": {
6
6
  "test": "test"
@@ -2,3 +2,4 @@ export declare function deleteFromArray<T>(arr: T[], component: T): boolean;
2
2
  export declare function quickDeleteFromArray<T>(arr: T[], component: T): boolean;
3
3
  export declare const negativeCallback: () => boolean;
4
4
  export declare const positiveCallback: () => boolean;
5
+ export declare const randomCallback: () => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.positiveCallback = exports.negativeCallback = exports.quickDeleteFromArray = exports.deleteFromArray = void 0;
3
+ exports.randomCallback = exports.positiveCallback = exports.negativeCallback = exports.quickDeleteFromArray = exports.deleteFromArray = void 0;
4
4
  function deleteFromArray(arr, component) {
5
5
  const index = arr.indexOf(component);
6
6
  if (index === -1)
@@ -22,3 +22,5 @@ const negativeCallback = () => false;
22
22
  exports.negativeCallback = negativeCallback;
23
23
  const positiveCallback = () => true;
24
24
  exports.positiveCallback = positiveCallback;
25
+ const randomCallback = () => "772716b8-e6e2-47ac-95e9-e8d99ce35124";
26
+ exports.randomCallback = randomCallback;
@@ -22,50 +22,39 @@ class SubscribeObject {
22
22
  }
23
23
  static callbackSend(value, subsObj) {
24
24
  const listener = subsObj.listener;
25
- if (!listener) {
26
- subsObj.unsubscribe();
25
+ if (!listener)
26
+ return subsObj.unsubscribe();
27
+ if (!subsObj.observable)
28
+ return subsObj.unsubscribe();
29
+ if (subsObj.isListenPaused)
27
30
  return;
31
+ if (!subsObj.isPipe)
32
+ return listener(value);
33
+ if (subsObj.emitByPositiveCondition && subsObj.emitByPositiveCondition(value))
34
+ return listener(value);
35
+ if (subsObj.emitByNegativeCondition && !subsObj.emitByNegativeCondition(value))
36
+ return listener(value);
37
+ if (subsObj.once.isOnce) {
38
+ subsObj.once.isFinished = true;
39
+ listener(value);
40
+ return subsObj.unsubscribe();
41
+ }
42
+ if (subsObj.unsubscribeByNegativeCondition) {
43
+ if (!subsObj.unsubscribeByNegativeCondition(value)) {
44
+ subsObj.unsubscribeByNegativeCondition = null;
45
+ return subsObj.unsubscribe();
46
+ }
47
+ return listener(value);
28
48
  }
29
- switch (true) {
30
- case !subsObj.observable:
31
- subsObj.unsubscribe();
32
- return;
33
- case subsObj.isListenPaused:
34
- return;
35
- case !subsObj.isPipe:
36
- listener(value);
37
- return;
38
- case subsObj.once.isOnce:
39
- subsObj.once.isFinished = true;
40
- listener(value);
41
- subsObj.unsubscribe();
42
- break;
43
- case !!subsObj.unsubscribeByNegativeCondition:
44
- if (!subsObj.unsubscribeByNegativeCondition(value)) {
45
- subsObj.unsubscribeByNegativeCondition = null;
46
- subsObj.unsubscribe();
47
- return;
48
- }
49
- listener(value);
50
- break;
51
- case !!subsObj.unsubscribeByPositiveCondition:
52
- if (subsObj.unsubscribeByPositiveCondition(value)) {
53
- subsObj.unsubscribeByPositiveCondition = null;
54
- subsObj.unsubscribe();
55
- return;
56
- }
57
- listener(value);
58
- break;
59
- case !!subsObj.emitByNegativeCondition:
60
- !subsObj.emitByNegativeCondition(value) && listener(value);
61
- break;
62
- case !!subsObj.emitByPositiveCondition:
63
- subsObj.emitByPositiveCondition(value) && listener(value);
64
- break;
65
- case !!subsObj.emitMatchCondition:
66
- (subsObj.emitMatchCondition(value) === value) && listener(value);
67
- break;
49
+ if (subsObj.unsubscribeByPositiveCondition) {
50
+ if (subsObj.unsubscribeByPositiveCondition(value)) {
51
+ subsObj.unsubscribeByPositiveCondition = null;
52
+ return subsObj.unsubscribe();
53
+ }
54
+ return listener(value);
68
55
  }
56
+ if (subsObj.emitMatchCondition && (subsObj.emitMatchCondition(value) === value))
57
+ return listener(value);
69
58
  }
70
59
  subscribe(listener, errorHandler) {
71
60
  this.listener = listener;
@@ -73,11 +62,11 @@ class SubscribeObject {
73
62
  return this;
74
63
  }
75
64
  unsubscribe() {
76
- if (this.observable) {
77
- this.observable.unSubscribe(this);
78
- this.observable = 0;
79
- this.listener = 0;
80
- }
65
+ if (!this.observable)
66
+ return;
67
+ this.observable.unSubscribe(this);
68
+ this.observable = 0;
69
+ this.listener = 0;
81
70
  }
82
71
  send(value) {
83
72
  try {
@@ -108,11 +97,7 @@ class SubscribeObject {
108
97
  return this;
109
98
  }
110
99
  emitMatch(condition) {
111
- const type = typeof condition;
112
- if (type !== "function") {
113
- condition = () => `ERROR CONDITION TYPE ${type}, CONTROL STATE ${this.observable && !this.observable.getValue()}`;
114
- }
115
- this.emitMatchCondition = condition;
100
+ this.emitMatchCondition = !!condition ? condition : FunctionLibs_1.randomCallback;
116
101
  return this;
117
102
  }
118
103
  resume() {
@@ -154,10 +139,8 @@ class Observable {
154
139
  return;
155
140
  this.isNextProcess = true;
156
141
  this.value = value;
157
- const length = this.listeners.length;
158
- for (let i = 0; i < length; i++) {
142
+ for (let i = 0; i < this.listeners.length; i++)
159
143
  this.listeners[i].send(value);
160
- }
161
144
  this.isNextProcess = false;
162
145
  this.listenersForUnsubscribe.length && this.handleListenersForUnsubscribe();
163
146
  }
@@ -166,16 +149,13 @@ class Observable {
166
149
  return;
167
150
  if (!this._isEnable)
168
151
  return;
169
- for (let i = 0; i < values.length; i++) {
152
+ for (let i = 0; i < values.length; i++)
170
153
  this.next(values[i]);
171
- }
172
154
  }
173
155
  handleListenersForUnsubscribe() {
174
156
  const length = this.listenersForUnsubscribe.length;
175
- for (let i = 0; i < length; i++) {
176
- const listener = this.listenersForUnsubscribe[i];
177
- this.unSubscribe(listener);
178
- }
157
+ for (let i = 0; i < length; i++)
158
+ this.unSubscribe(this.listenersForUnsubscribe[i]);
179
159
  this.listenersForUnsubscribe.length = 0;
180
160
  }
181
161
  unSubscribe(listener) {