evg_observable 1.1.28 → 1.1.30

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/MIT ADDED
@@ -0,0 +1,22 @@
1
+
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2021 Grif
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evg_observable",
3
- "version": "1.1.28",
3
+ "version": "1.1.30",
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": "LICENSE.md",
19
+ "license": "MIT",
20
20
  "bugs": {
21
21
  "url": "https://github.com/BarushevEA/light-observable-ts/issues"
22
22
  },
@@ -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,13 +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 asyncSend;
15
+ private static callbackSend;
16
16
  subscribe(listener: IListener<T>): ISubscriptionLike<T>;
17
17
  unsubscribe(): void;
18
18
  send(value: T): void;
19
- private sendValueToListener;
20
19
  setOnce(): ISubscribe<T>;
21
20
  unsubscribeByNegative(condition: ICallback<any>): ISubscribe<T>;
22
21
  unsubscribeByPositive(condition: ICallback<any>): ISubscribe<T>;
@@ -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,77 +13,70 @@ 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 asyncSend(value, subsObj) {
19
+ static callbackSend(value, subsObj) {
20
20
  const listener = subsObj.listener;
21
- return new Promise((resolve => {
22
- switch (true) {
23
- case !subsObj.observable:
24
- case !listener:
21
+ switch (true) {
22
+ case !subsObj.observable:
23
+ case !listener:
24
+ subsObj.unsubscribe();
25
+ return;
26
+ case subsObj.isListenPaused:
27
+ return;
28
+ case subsObj.once.isOnce:
29
+ subsObj.once.isFinished = true;
30
+ listener && listener((value));
31
+ subsObj.unsubscribe();
32
+ break;
33
+ case !!subsObj.unsubscribeByNegativeCondition:
34
+ if (!subsObj.unsubscribeByNegativeCondition()) {
35
+ subsObj.unsubscribeByNegativeCondition = null;
25
36
  subsObj.unsubscribe();
26
- resolve(false);
27
- return;
28
- case subsObj.isListenPaused:
29
- resolve(false);
30
37
  return;
31
- case subsObj.once.isOnce:
32
- subsObj.once.isFinished = true;
33
- listener && listener((value));
38
+ }
39
+ listener && listener((value));
40
+ break;
41
+ case !!subsObj.unsubscribeByPositiveCondition:
42
+ if (subsObj.unsubscribeByPositiveCondition()) {
43
+ subsObj.unsubscribeByPositiveCondition = null;
34
44
  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
- }));
45
+ return;
46
+ }
47
+ listener && listener((value));
48
+ break;
49
+ case !!subsObj.emitByNegativeCondition:
50
+ !subsObj.emitByNegativeCondition() && listener && listener(value);
51
+ break;
52
+ case !!subsObj.emitByPositiveCondition:
53
+ subsObj.emitByPositiveCondition() && listener && listener(value);
54
+ break;
55
+ case !!subsObj.emitMatchCondition:
56
+ (subsObj.emitMatchCondition() === value) && listener && listener(value);
57
+ break;
58
+ default:
59
+ listener && listener((value));
60
+ }
66
61
  }
67
62
  subscribe(listener) {
68
63
  this.listener = listener;
69
64
  return this;
70
65
  }
71
66
  unsubscribe() {
72
- if (!!this.observable) {
67
+ if (this.observable) {
73
68
  this.observable.unSubscribe(this);
74
69
  this.observable = 0;
75
70
  this.listener = 0;
76
71
  }
77
72
  }
78
73
  send(value) {
79
- this.sendValueToListener(value);
80
- }
81
- sendValueToListener(value) {
82
- SubscribeObject.asyncSend(value, this)
83
- .catch(err => {
84
- console.log('(Unit of SubscribeObject).send(value: T) call .sendValueToListener(value: T) ERROR:', err);
85
- });
74
+ try {
75
+ SubscribeObject.callbackSend(value, this);
76
+ }
77
+ catch (err) {
78
+ console.log('(Unit of SubscribeObject).send(value: T) ERROR:', err);
79
+ }
86
80
  }
87
81
  setOnce() {
88
82
  this.once.isOnce = true;
@@ -158,8 +152,8 @@ class Observable {
158
152
  return;
159
153
  this.value = value;
160
154
  this.isNextProcess = true;
161
- for (let i = 0; i < this.listeners.length; i++)
162
- this.listeners[i].send(value);
155
+ for (const listener of this.listeners)
156
+ listener && listener.send(value);
163
157
  this.isNextProcess = false;
164
158
  this.handleListenersForUnsubscribe();
165
159
  }
@@ -210,6 +204,8 @@ class Observable {
210
204
  subscribe(listener) {
211
205
  if (this._isDestroyed)
212
206
  return undefined;
207
+ if (!listener)
208
+ return undefined;
213
209
  const subscribeObject = new SubscribeObject(this, listener);
214
210
  this.listeners.push(subscribeObject);
215
211
  return subscribeObject;
@@ -1,5 +1,5 @@
1
1
  import { Observable, SubscribeObject } from "./Observable";
2
- import { ICallback, IListener, IOrdered, IOrderedSetup, IOrderedSubscribe, IOrderedSubscriptionLike, ISubscriptionLike } from "./Types";
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>): ISubscriptionLike<T> | undefined;
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;
@@ -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
  };