evg_observable 1.1.27 → 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.27",
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": "MIT",
19
+ "license": "LICENSE.md",
20
20
  "bugs": {
21
21
  "url": "https://github.com/BarushevEA/light-observable-ts/issues"
22
22
  },
@@ -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
- this.list.push(subscriptionLikeList[i]);
14
+ const subscription = subscriptionLikeList[i];
15
+ subscription && this.list.push(subscription);
15
16
  }
16
17
  }
17
18
  unsubscribe(subscriptionLike) {
@@ -12,6 +12,7 @@ export declare class SubscribeObject<T> implements ISubscribeObject<T>, IMarkedF
12
12
  private emitMatchCondition;
13
13
  protected _order: number;
14
14
  constructor(observable?: IObserver<T>, listener?: IListener<T>);
15
+ private static asyncSend;
15
16
  subscribe(listener: IListener<T>): ISubscriptionLike<T>;
16
17
  unsubscribe(): void;
17
18
  send(value: T): void;
@@ -16,6 +16,54 @@ class SubscribeObject {
16
16
  this.observable = observable;
17
17
  this.listener = listener;
18
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
+ }
19
67
  subscribe(listener) {
20
68
  this.listener = listener;
21
69
  return this;
@@ -31,53 +79,7 @@ class SubscribeObject {
31
79
  this.sendValueToListener(value);
32
80
  }
33
81
  sendValueToListener(value) {
34
- const asyncSend = (value) => {
35
- const listener = this.listener;
36
- return new Promise((resolve => {
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)
82
+ SubscribeObject.asyncSend(value, this)
81
83
  .catch(err => {
82
84
  console.log('(Unit of SubscribeObject).send(value: T) call .sendValueToListener(value: T) ERROR:', err);
83
85
  });