evg_observable 1.1.20 → 1.1.24

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.20",
3
+ "version": "1.1.24",
4
4
  "description": "Light observable",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -22,13 +22,13 @@
22
22
  },
23
23
  "homepage": "https://github.com/BarushevEA/light-observable-ts#readme",
24
24
  "devDependencies": {
25
- "typescript": "^4.4.3",
26
- "@testdeck/mocha": "^0.1.2",
27
- "@types/chai": "^4.2.22",
28
- "chai": "^4.3.4",
29
- "mocha": "^9.1.2",
25
+ "typescript": "^4.5.5",
26
+ "@testdeck/mocha": "^0.2.0",
27
+ "@types/chai": "^4.3.0",
28
+ "chai": "^4.3.6",
29
+ "mocha": "^9.2.0",
30
30
  "nyc": "^15.1.0",
31
- "ts-node": "^10.2.1"
31
+ "ts-node": "^10.4.0"
32
32
  },
33
33
  "keywords": [
34
34
  "EVG Observable",
@@ -14,6 +14,7 @@ export declare class SubscribeObject<T> implements ISubscribeObject<T> {
14
14
  subscribe(listener: IListener<T>): ISubscriptionLike<T>;
15
15
  unsubscribe(): void;
16
16
  send(value: T): void;
17
+ private sendValueToListener;
17
18
  setOnce(): ISubscribe<T>;
18
19
  unsubscribeByNegative(condition: ICallback<any>): ISubscribe<T>;
19
20
  unsubscribeByPositive(condition: ICallback<any>): ISubscribe<T>;
@@ -27,46 +27,59 @@ class SubscribeObject {
27
27
  }
28
28
  }
29
29
  send(value) {
30
- switch (true) {
31
- case !this.observable:
32
- case !this.listener:
33
- this.unsubscribe();
34
- return;
35
- case this.isListenPaused:
36
- return;
37
- case this.once.isOnce:
38
- this.once.isFinished = true;
39
- this.listener(value);
40
- this.unsubscribe();
41
- break;
42
- case !!this.unsubscribeByNegativeCondition:
43
- if (!this.unsubscribeByNegativeCondition()) {
44
- this.unsubscribeByNegativeCondition = null;
45
- this.unsubscribe();
46
- return;
30
+ this.sendValueToListener(value);
31
+ }
32
+ sendValueToListener(value) {
33
+ const asyncSend = () => {
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((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((value));
55
+ break;
56
+ case !!this.unsubscribeByPositiveCondition:
57
+ if (this.unsubscribeByPositiveCondition()) {
58
+ this.unsubscribeByPositiveCondition = null;
59
+ this.unsubscribe();
60
+ return;
61
+ }
62
+ listener((value));
63
+ break;
64
+ case !!this.emitByNegativeCondition:
65
+ !this.emitByNegativeCondition() && listener(value);
66
+ break;
67
+ case !!this.emitByPositiveCondition:
68
+ this.emitByPositiveCondition() && listener(value);
69
+ break;
70
+ case !!this.emitMatchCondition:
71
+ (this.emitMatchCondition() === value) && listener(value);
72
+ break;
73
+ default:
74
+ listener((value));
47
75
  }
48
- this.listener(value);
49
- break;
50
- case !!this.unsubscribeByPositiveCondition:
51
- if (this.unsubscribeByPositiveCondition()) {
52
- this.unsubscribeByPositiveCondition = null;
53
- this.unsubscribe();
54
- return;
55
- }
56
- this.listener(value);
57
- break;
58
- case !!this.emitByNegativeCondition:
59
- !this.emitByNegativeCondition() && this.listener(value);
60
- break;
61
- case !!this.emitByPositiveCondition:
62
- this.emitByPositiveCondition() && this.listener(value);
63
- break;
64
- case !!this.emitMatchCondition:
65
- (this.emitMatchCondition() === value) && this.listener(value);
66
- break;
67
- default:
68
- this.listener(value);
69
- }
76
+ resolve(true);
77
+ }));
78
+ };
79
+ asyncSend()
80
+ .catch(err => {
81
+ console.log('(Unit of SubscribeObject).send(value: T) call .sendValueToListener(value: T) ERROR:', err);
82
+ });
70
83
  }
71
84
  setOnce() {
72
85
  this.once.isOnce = true;