evg_observable 1.1.27 → 1.1.29
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.29",
|
|
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) {
|
|
@@ -3,6 +3,7 @@ export declare class SubscribeObject<T> implements ISubscribeObject<T>, IMarkedF
|
|
|
3
3
|
isMarkedForUnsubscribe: boolean;
|
|
4
4
|
protected observable: IObserver<T> | undefined;
|
|
5
5
|
protected listener: IListener<T> | undefined;
|
|
6
|
+
protected _order: number;
|
|
6
7
|
private isListenPaused;
|
|
7
8
|
private once;
|
|
8
9
|
private unsubscribeByNegativeCondition;
|
|
@@ -10,12 +11,11 @@ export declare class SubscribeObject<T> implements ISubscribeObject<T>, IMarkedF
|
|
|
10
11
|
private emitByNegativeCondition;
|
|
11
12
|
private emitByPositiveCondition;
|
|
12
13
|
private emitMatchCondition;
|
|
13
|
-
protected _order: number;
|
|
14
14
|
constructor(observable?: IObserver<T>, listener?: IListener<T>);
|
|
15
|
+
private static callbackSend;
|
|
15
16
|
subscribe(listener: IListener<T>): ISubscriptionLike<T>;
|
|
16
17
|
unsubscribe(): void;
|
|
17
18
|
send(value: T): void;
|
|
18
|
-
private sendValueToListener;
|
|
19
19
|
setOnce(): ISubscribe<T>;
|
|
20
20
|
unsubscribeByNegative(condition: ICallback<any>): ISubscribe<T>;
|
|
21
21
|
unsubscribeByPositive(condition: ICallback<any>): ISubscribe<T>;
|
package/src/outLib/Observable.js
CHANGED
|
@@ -5,6 +5,7 @@ const FunctionLibs_1 = require("./FunctionLibs");
|
|
|
5
5
|
class SubscribeObject {
|
|
6
6
|
constructor(observable, listener) {
|
|
7
7
|
this.isMarkedForUnsubscribe = false;
|
|
8
|
+
this._order = 0;
|
|
8
9
|
this.isListenPaused = false;
|
|
9
10
|
this.once = { isOnce: false, isFinished: false };
|
|
10
11
|
this.unsubscribeByNegativeCondition = null;
|
|
@@ -12,75 +13,71 @@ class SubscribeObject {
|
|
|
12
13
|
this.emitByNegativeCondition = null;
|
|
13
14
|
this.emitByPositiveCondition = null;
|
|
14
15
|
this.emitMatchCondition = null;
|
|
15
|
-
this._order = 0;
|
|
16
16
|
this.observable = observable;
|
|
17
17
|
this.listener = listener;
|
|
18
18
|
}
|
|
19
|
+
static callbackSend(value, subsObj) {
|
|
20
|
+
const listener = subsObj.listener;
|
|
21
|
+
switch (true) {
|
|
22
|
+
case !subsObj.observable:
|
|
23
|
+
case !listener:
|
|
24
|
+
subsObj.unsubscribe();
|
|
25
|
+
return;
|
|
26
|
+
case subsObj.isListenPaused:
|
|
27
|
+
;
|
|
28
|
+
return;
|
|
29
|
+
case subsObj.once.isOnce:
|
|
30
|
+
subsObj.once.isFinished = true;
|
|
31
|
+
listener && listener((value));
|
|
32
|
+
subsObj.unsubscribe();
|
|
33
|
+
break;
|
|
34
|
+
case !!subsObj.unsubscribeByNegativeCondition:
|
|
35
|
+
if (!subsObj.unsubscribeByNegativeCondition()) {
|
|
36
|
+
subsObj.unsubscribeByNegativeCondition = null;
|
|
37
|
+
subsObj.unsubscribe();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
listener && listener((value));
|
|
41
|
+
break;
|
|
42
|
+
case !!subsObj.unsubscribeByPositiveCondition:
|
|
43
|
+
if (subsObj.unsubscribeByPositiveCondition()) {
|
|
44
|
+
subsObj.unsubscribeByPositiveCondition = null;
|
|
45
|
+
subsObj.unsubscribe();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
listener && listener((value));
|
|
49
|
+
break;
|
|
50
|
+
case !!subsObj.emitByNegativeCondition:
|
|
51
|
+
!subsObj.emitByNegativeCondition() && listener && listener(value);
|
|
52
|
+
break;
|
|
53
|
+
case !!subsObj.emitByPositiveCondition:
|
|
54
|
+
subsObj.emitByPositiveCondition() && listener && listener(value);
|
|
55
|
+
break;
|
|
56
|
+
case !!subsObj.emitMatchCondition:
|
|
57
|
+
(subsObj.emitMatchCondition() === value) && listener && listener(value);
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
listener && listener((value));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
19
63
|
subscribe(listener) {
|
|
20
64
|
this.listener = listener;
|
|
21
65
|
return this;
|
|
22
66
|
}
|
|
23
67
|
unsubscribe() {
|
|
24
|
-
if (
|
|
68
|
+
if (this.observable) {
|
|
25
69
|
this.observable.unSubscribe(this);
|
|
26
70
|
this.observable = 0;
|
|
27
71
|
this.listener = 0;
|
|
28
72
|
}
|
|
29
73
|
}
|
|
30
74
|
send(value) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
switch (true) {
|
|
38
|
-
case !this.observable:
|
|
39
|
-
case !listener:
|
|
40
|
-
this.unsubscribe();
|
|
41
|
-
return;
|
|
42
|
-
case this.isListenPaused:
|
|
43
|
-
return;
|
|
44
|
-
case this.once.isOnce:
|
|
45
|
-
this.once.isFinished = true;
|
|
46
|
-
listener && listener((value));
|
|
47
|
-
this.unsubscribe();
|
|
48
|
-
break;
|
|
49
|
-
case !!this.unsubscribeByNegativeCondition:
|
|
50
|
-
if (!this.unsubscribeByNegativeCondition()) {
|
|
51
|
-
this.unsubscribeByNegativeCondition = null;
|
|
52
|
-
this.unsubscribe();
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
listener && listener((value));
|
|
56
|
-
break;
|
|
57
|
-
case !!this.unsubscribeByPositiveCondition:
|
|
58
|
-
if (this.unsubscribeByPositiveCondition()) {
|
|
59
|
-
this.unsubscribeByPositiveCondition = null;
|
|
60
|
-
this.unsubscribe();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
listener && listener((value));
|
|
64
|
-
break;
|
|
65
|
-
case !!this.emitByNegativeCondition:
|
|
66
|
-
!this.emitByNegativeCondition() && listener && listener(value);
|
|
67
|
-
break;
|
|
68
|
-
case !!this.emitByPositiveCondition:
|
|
69
|
-
this.emitByPositiveCondition() && listener && listener(value);
|
|
70
|
-
break;
|
|
71
|
-
case !!this.emitMatchCondition:
|
|
72
|
-
(this.emitMatchCondition() === value) && listener && listener(value);
|
|
73
|
-
break;
|
|
74
|
-
default:
|
|
75
|
-
listener && listener((value));
|
|
76
|
-
}
|
|
77
|
-
resolve(true);
|
|
78
|
-
}));
|
|
79
|
-
};
|
|
80
|
-
asyncSend(value)
|
|
81
|
-
.catch(err => {
|
|
82
|
-
console.log('(Unit of SubscribeObject).send(value: T) call .sendValueToListener(value: T) ERROR:', err);
|
|
83
|
-
});
|
|
75
|
+
try {
|
|
76
|
+
SubscribeObject.callbackSend(value, this);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
console.log('(Unit of SubscribeObject).send(value: T) ERROR:', err);
|
|
80
|
+
}
|
|
84
81
|
}
|
|
85
82
|
setOnce() {
|
|
86
83
|
this.once.isOnce = true;
|
|
@@ -156,8 +153,8 @@ class Observable {
|
|
|
156
153
|
return;
|
|
157
154
|
this.value = value;
|
|
158
155
|
this.isNextProcess = true;
|
|
159
|
-
for (
|
|
160
|
-
|
|
156
|
+
for (const listener of this.listeners)
|
|
157
|
+
listener && listener.send(value);
|
|
161
158
|
this.isNextProcess = false;
|
|
162
159
|
this.handleListenersForUnsubscribe();
|
|
163
160
|
}
|
|
@@ -208,6 +205,8 @@ class Observable {
|
|
|
208
205
|
subscribe(listener) {
|
|
209
206
|
if (this._isDestroyed)
|
|
210
207
|
return undefined;
|
|
208
|
+
if (!listener)
|
|
209
|
+
return undefined;
|
|
211
210
|
const subscribeObject = new SubscribeObject(this, listener);
|
|
212
211
|
this.listeners.push(subscribeObject);
|
|
213
212
|
return subscribeObject;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable, SubscribeObject } from "./Observable";
|
|
2
|
-
import { ICallback, IListener, IOrdered, IOrderedSetup, IOrderedSubscribe, IOrderedSubscriptionLike
|
|
2
|
+
import { ICallback, IListener, IOrdered, IOrderedSetup, IOrderedSubscribe, IOrderedSubscriptionLike } from "./Types";
|
|
3
3
|
export declare class OrderedSubscribeObject<T> extends SubscribeObject<T> {
|
|
4
4
|
constructor(observable: OrderedObservable<T> | IOrdered<T>, listener?: IListener<T>);
|
|
5
5
|
get order(): number;
|
|
@@ -14,6 +14,6 @@ export declare class OrderedSubscribeObject<T> extends SubscribeObject<T> {
|
|
|
14
14
|
}
|
|
15
15
|
export declare class OrderedObservable<T> extends Observable<T> implements IOrdered<T> {
|
|
16
16
|
sortByOrder(): void;
|
|
17
|
-
subscribe(listener: IListener<T>):
|
|
17
|
+
subscribe(listener: IListener<T>): IOrderedSubscriptionLike<T> | undefined;
|
|
18
18
|
pipe(): IOrderedSetup<T> | undefined;
|
|
19
19
|
}
|
|
@@ -57,6 +57,8 @@ class OrderedObservable extends Observable_1.Observable {
|
|
|
57
57
|
subscribe(listener) {
|
|
58
58
|
if (this._isDestroyed)
|
|
59
59
|
return undefined;
|
|
60
|
+
if (!listener)
|
|
61
|
+
return undefined;
|
|
60
62
|
const subscribeObject = new OrderedSubscribeObject(this, listener);
|
|
61
63
|
this.listeners.push(subscribeObject);
|
|
62
64
|
return subscribeObject;
|
package/src/outLib/Types.d.ts
CHANGED
|
@@ -94,7 +94,7 @@ export type IOrderedObservable = {
|
|
|
94
94
|
sortByOrder(): void;
|
|
95
95
|
};
|
|
96
96
|
export type IOrdered<T> = IObserver<T> & IOrderedObservable;
|
|
97
|
-
export type IOrderedSubscriptionLike<T> = ISubscriptionLike<T> & IOrder;
|
|
97
|
+
export type IOrderedSubscriptionLike<T> = (ISubscriptionLike<T> & IOrder);
|
|
98
98
|
export type IOrderedSubscribe<T> = {
|
|
99
99
|
subscribe(listener: IListener<T>): IOrderedSubscriptionLike<T>;
|
|
100
100
|
};
|