evg_observable 1.1.26 → 1.1.28
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "evg_observable",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.28",
|
|
4
4
|
"description": "Light observable",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"url": "git+https://github.com/BarushevEA/light-observable-ts.git"
|
|
17
17
|
},
|
|
18
18
|
"author": "Barushev E.A.",
|
|
19
|
-
"license": "
|
|
19
|
+
"license": "LICENSE.md",
|
|
20
20
|
"bugs": {
|
|
21
21
|
"url": "https://github.com/BarushevEA/light-observable-ts/issues"
|
|
22
22
|
},
|
package/src/outLib/Collector.js
CHANGED
|
@@ -11,7 +11,8 @@ class Collector {
|
|
|
11
11
|
if (this._isDestroyed)
|
|
12
12
|
return null;
|
|
13
13
|
for (let i = 0; i < subscriptionLikeList.length; i++) {
|
|
14
|
-
|
|
14
|
+
const subscription = subscriptionLikeList[i];
|
|
15
|
+
subscription && this.list.push(subscription);
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
unsubscribe(subscriptionLike) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ICallback, IListener, IObserver, ISetup, ISubscribe, ISubscribeObject, ISubscriptionLike } from "./Types";
|
|
2
|
-
export declare class SubscribeObject<T> implements ISubscribeObject<T
|
|
1
|
+
import { ICallback, IListener, IMarkedForUnsubscribe, IObserver, ISetup, ISubscribe, ISubscribeObject, ISubscriptionLike } from "./Types";
|
|
2
|
+
export declare class SubscribeObject<T> implements ISubscribeObject<T>, IMarkedForUnsubscribe {
|
|
3
|
+
isMarkedForUnsubscribe: boolean;
|
|
3
4
|
protected observable: IObserver<T> | undefined;
|
|
4
5
|
protected listener: IListener<T> | undefined;
|
|
5
6
|
private isListenPaused;
|
|
@@ -11,6 +12,7 @@ export declare class SubscribeObject<T> implements ISubscribeObject<T> {
|
|
|
11
12
|
private emitMatchCondition;
|
|
12
13
|
protected _order: number;
|
|
13
14
|
constructor(observable?: IObserver<T>, listener?: IListener<T>);
|
|
15
|
+
private static asyncSend;
|
|
14
16
|
subscribe(listener: IListener<T>): ISubscriptionLike<T>;
|
|
15
17
|
unsubscribe(): void;
|
|
16
18
|
send(value: T): void;
|
package/src/outLib/Observable.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.Observable = exports.SubscribeObject = void 0;
|
|
|
4
4
|
const FunctionLibs_1 = require("./FunctionLibs");
|
|
5
5
|
class SubscribeObject {
|
|
6
6
|
constructor(observable, listener) {
|
|
7
|
+
this.isMarkedForUnsubscribe = false;
|
|
7
8
|
this.isListenPaused = false;
|
|
8
9
|
this.once = { isOnce: false, isFinished: false };
|
|
9
10
|
this.unsubscribeByNegativeCondition = null;
|
|
@@ -15,6 +16,54 @@ class SubscribeObject {
|
|
|
15
16
|
this.observable = observable;
|
|
16
17
|
this.listener = listener;
|
|
17
18
|
}
|
|
19
|
+
static asyncSend(value, subsObj) {
|
|
20
|
+
const listener = subsObj.listener;
|
|
21
|
+
return new Promise((resolve => {
|
|
22
|
+
switch (true) {
|
|
23
|
+
case !subsObj.observable:
|
|
24
|
+
case !listener:
|
|
25
|
+
subsObj.unsubscribe();
|
|
26
|
+
resolve(false);
|
|
27
|
+
return;
|
|
28
|
+
case subsObj.isListenPaused:
|
|
29
|
+
resolve(false);
|
|
30
|
+
return;
|
|
31
|
+
case subsObj.once.isOnce:
|
|
32
|
+
subsObj.once.isFinished = true;
|
|
33
|
+
listener && listener((value));
|
|
34
|
+
subsObj.unsubscribe();
|
|
35
|
+
break;
|
|
36
|
+
case !!subsObj.unsubscribeByNegativeCondition:
|
|
37
|
+
if (!subsObj.unsubscribeByNegativeCondition()) {
|
|
38
|
+
subsObj.unsubscribeByNegativeCondition = null;
|
|
39
|
+
subsObj.unsubscribe();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
listener && listener((value));
|
|
43
|
+
break;
|
|
44
|
+
case !!subsObj.unsubscribeByPositiveCondition:
|
|
45
|
+
if (subsObj.unsubscribeByPositiveCondition()) {
|
|
46
|
+
subsObj.unsubscribeByPositiveCondition = null;
|
|
47
|
+
subsObj.unsubscribe();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
listener && listener((value));
|
|
51
|
+
break;
|
|
52
|
+
case !!subsObj.emitByNegativeCondition:
|
|
53
|
+
!subsObj.emitByNegativeCondition() && listener && listener(value);
|
|
54
|
+
break;
|
|
55
|
+
case !!subsObj.emitByPositiveCondition:
|
|
56
|
+
subsObj.emitByPositiveCondition() && listener && listener(value);
|
|
57
|
+
break;
|
|
58
|
+
case !!subsObj.emitMatchCondition:
|
|
59
|
+
(subsObj.emitMatchCondition() === value) && listener && listener(value);
|
|
60
|
+
break;
|
|
61
|
+
default:
|
|
62
|
+
listener && listener((value));
|
|
63
|
+
}
|
|
64
|
+
resolve(true);
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
18
67
|
subscribe(listener) {
|
|
19
68
|
this.listener = listener;
|
|
20
69
|
return this;
|
|
@@ -30,53 +79,7 @@ class SubscribeObject {
|
|
|
30
79
|
this.sendValueToListener(value);
|
|
31
80
|
}
|
|
32
81
|
sendValueToListener(value) {
|
|
33
|
-
|
|
34
|
-
const listener = this.listener;
|
|
35
|
-
return new Promise((resolve => {
|
|
36
|
-
switch (true) {
|
|
37
|
-
case !this.observable:
|
|
38
|
-
case !listener:
|
|
39
|
-
this.unsubscribe();
|
|
40
|
-
return;
|
|
41
|
-
case this.isListenPaused:
|
|
42
|
-
return;
|
|
43
|
-
case this.once.isOnce:
|
|
44
|
-
this.once.isFinished = true;
|
|
45
|
-
listener && listener((value));
|
|
46
|
-
this.unsubscribe();
|
|
47
|
-
break;
|
|
48
|
-
case !!this.unsubscribeByNegativeCondition:
|
|
49
|
-
if (!this.unsubscribeByNegativeCondition()) {
|
|
50
|
-
this.unsubscribeByNegativeCondition = null;
|
|
51
|
-
this.unsubscribe();
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
listener && listener((value));
|
|
55
|
-
break;
|
|
56
|
-
case !!this.unsubscribeByPositiveCondition:
|
|
57
|
-
if (this.unsubscribeByPositiveCondition()) {
|
|
58
|
-
this.unsubscribeByPositiveCondition = null;
|
|
59
|
-
this.unsubscribe();
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
listener && listener((value));
|
|
63
|
-
break;
|
|
64
|
-
case !!this.emitByNegativeCondition:
|
|
65
|
-
!this.emitByNegativeCondition() && listener && listener(value);
|
|
66
|
-
break;
|
|
67
|
-
case !!this.emitByPositiveCondition:
|
|
68
|
-
this.emitByPositiveCondition() && listener && listener(value);
|
|
69
|
-
break;
|
|
70
|
-
case !!this.emitMatchCondition:
|
|
71
|
-
(this.emitMatchCondition() === value) && listener && listener(value);
|
|
72
|
-
break;
|
|
73
|
-
default:
|
|
74
|
-
listener && listener((value));
|
|
75
|
-
}
|
|
76
|
-
resolve(true);
|
|
77
|
-
}));
|
|
78
|
-
};
|
|
79
|
-
asyncSend(value)
|
|
82
|
+
SubscribeObject.asyncSend(value, this)
|
|
80
83
|
.catch(err => {
|
|
81
84
|
console.log('(Unit of SubscribeObject).send(value: T) call .sendValueToListener(value: T) ERROR:', err);
|
|
82
85
|
});
|
|
@@ -170,7 +173,9 @@ class Observable {
|
|
|
170
173
|
if (this._isDestroyed)
|
|
171
174
|
return;
|
|
172
175
|
if (this.isNextProcess) {
|
|
173
|
-
|
|
176
|
+
const marker = listener;
|
|
177
|
+
!marker.isMarkedForUnsubscribe && this.listenersForUnsubscribe.push(listener);
|
|
178
|
+
marker.isMarkedForUnsubscribe = true;
|
|
174
179
|
return;
|
|
175
180
|
}
|
|
176
181
|
this.listeners &&
|
package/src/outLib/Types.d.ts
CHANGED