evg_observable 1.1.24 → 1.1.26

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/README.md CHANGED
@@ -19,18 +19,6 @@ EVG Observable - is a small library for serving asynchronous events.
19
19
 
20
20
  # Usage
21
21
 
22
- ### tsconfig.json
23
-
24
- recommended value of the "strict" field in the configuration
25
-
26
- ```json
27
- {
28
- "compilerOptions": {
29
- "strict": false
30
- }
31
- }
32
- ```
33
-
34
22
  ## Observable simple usage
35
23
 
36
24
  ```ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evg_observable",
3
- "version": "1.1.24",
3
+ "version": "1.1.26",
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.5.5",
26
- "@testdeck/mocha": "^0.2.0",
27
- "@types/chai": "^4.3.0",
28
- "chai": "^4.3.6",
29
- "mocha": "^9.2.0",
25
+ "typescript": "^4.9.4",
26
+ "@testdeck/mocha": "^0.3.3",
27
+ "@types/chai": "^4.3.4",
28
+ "chai": "^4.3.7",
29
+ "mocha": "^10.2.0",
30
30
  "nyc": "^15.1.0",
31
- "ts-node": "^10.4.0"
31
+ "ts-node": "^10.9.1"
32
32
  },
33
33
  "keywords": [
34
34
  "EVG Observable",
@@ -2,9 +2,9 @@ import { ICollector, ISubscriptionLike } from "./Types";
2
2
  export declare class Collector implements ICollector {
3
3
  protected list: ISubscriptionLike<any>[];
4
4
  private _isDestroyed;
5
- collect(...subscriptionLikeList: ISubscriptionLike<any>[]): void;
6
- unsubscribe(subscriptionLike: ISubscriptionLike<any>): void;
7
- unsubscribeAll(): void;
5
+ collect(...subscriptionLikeList: ISubscriptionLike<any>[]): void | null;
6
+ unsubscribe(subscriptionLike: ISubscriptionLike<any> | undefined): void | null;
7
+ unsubscribeAll(): void | null;
8
8
  size(): number;
9
9
  destroy(): void;
10
10
  get isDestroyed(): boolean;
@@ -1,7 +1,7 @@
1
1
  import { ICallback, IListener, IObserver, ISetup, ISubscribe, ISubscribeObject, ISubscriptionLike } from "./Types";
2
2
  export declare class SubscribeObject<T> implements ISubscribeObject<T> {
3
- protected observable: IObserver<T>;
4
- protected listener: IListener<T>;
3
+ protected observable: IObserver<T> | undefined;
4
+ protected listener: IListener<T> | undefined;
5
5
  private isListenPaused;
6
6
  private once;
7
7
  private unsubscribeByNegativeCondition;
@@ -42,9 +42,9 @@ export declare class Observable<T> implements IObserver<T> {
42
42
  unSubscribe(listener: ISubscriptionLike<T>): void;
43
43
  destroy(): void;
44
44
  unsubscribeAll(): void;
45
- getValue(): T;
45
+ getValue(): T | undefined;
46
46
  size(): number;
47
- subscribe(listener: IListener<T>): ISubscriptionLike<T>;
48
- pipe(): ISetup<T>;
47
+ subscribe(listener: IListener<T>): ISubscriptionLike<T> | undefined;
48
+ pipe(): ISetup<T> | undefined;
49
49
  get isDestroyed(): boolean;
50
50
  }
@@ -30,7 +30,7 @@ class SubscribeObject {
30
30
  this.sendValueToListener(value);
31
31
  }
32
32
  sendValueToListener(value) {
33
- const asyncSend = () => {
33
+ const asyncSend = (value) => {
34
34
  const listener = this.listener;
35
35
  return new Promise((resolve => {
36
36
  switch (true) {
@@ -42,7 +42,7 @@ class SubscribeObject {
42
42
  return;
43
43
  case this.once.isOnce:
44
44
  this.once.isFinished = true;
45
- listener((value));
45
+ listener && listener((value));
46
46
  this.unsubscribe();
47
47
  break;
48
48
  case !!this.unsubscribeByNegativeCondition:
@@ -51,7 +51,7 @@ class SubscribeObject {
51
51
  this.unsubscribe();
52
52
  return;
53
53
  }
54
- listener((value));
54
+ listener && listener((value));
55
55
  break;
56
56
  case !!this.unsubscribeByPositiveCondition:
57
57
  if (this.unsubscribeByPositiveCondition()) {
@@ -59,24 +59,24 @@ class SubscribeObject {
59
59
  this.unsubscribe();
60
60
  return;
61
61
  }
62
- listener((value));
62
+ listener && listener((value));
63
63
  break;
64
64
  case !!this.emitByNegativeCondition:
65
- !this.emitByNegativeCondition() && listener(value);
65
+ !this.emitByNegativeCondition() && listener && listener(value);
66
66
  break;
67
67
  case !!this.emitByPositiveCondition:
68
- this.emitByPositiveCondition() && listener(value);
68
+ this.emitByPositiveCondition() && listener && listener(value);
69
69
  break;
70
70
  case !!this.emitMatchCondition:
71
- (this.emitMatchCondition() === value) && listener(value);
71
+ (this.emitMatchCondition() === value) && listener && listener(value);
72
72
  break;
73
73
  default:
74
- listener((value));
74
+ listener && listener((value));
75
75
  }
76
76
  resolve(true);
77
77
  }));
78
78
  };
79
- asyncSend()
79
+ asyncSend(value)
80
80
  .catch(err => {
81
81
  console.log('(Unit of SubscribeObject).send(value: T) call .sendValueToListener(value: T) ERROR:', err);
82
82
  });
@@ -111,7 +111,8 @@ class SubscribeObject {
111
111
  }
112
112
  emitMatch(condition) {
113
113
  if (typeof condition !== "function")
114
- condition = () => `ERROR CONDITION TYPE ${typeof condition}, CONTROL STATE ${!this.observable.getValue()}`;
114
+ condition =
115
+ () => `ERROR CONDITION TYPE ${typeof condition}, CONTROL STATE ${this.observable && !this.observable.getValue()}`;
115
116
  this.emitMatchCondition = condition;
116
117
  return this;
117
118
  }
@@ -184,9 +185,12 @@ class Observable {
184
185
  unsubscribeAll() {
185
186
  if (this._isDestroyed)
186
187
  return;
187
- const length = this.listeners.length;
188
- for (let i = 0; i < length; i++)
189
- (this.listeners.pop()).unsubscribe();
188
+ const listeners = this.listeners;
189
+ const length = listeners.length;
190
+ for (let i = 0; i < length; i++) {
191
+ const subscriber = listeners.pop();
192
+ subscriber && subscriber.unsubscribe();
193
+ }
190
194
  }
191
195
  getValue() {
192
196
  if (this._isDestroyed)
@@ -1,5 +1,5 @@
1
1
  import { Observable, SubscribeObject } from "./Observable";
2
- import { ICallback, IListener, IOrdered, IOrderedSetup, IOrderedSubscribe, IOrderedSubscriptionLike } from "./Types";
2
+ import { ICallback, IListener, IOrdered, IOrderedSetup, IOrderedSubscribe, IOrderedSubscriptionLike, ISubscriptionLike } 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>): IOrderedSubscriptionLike<T>;
18
- pipe(): IOrderedSetup<T>;
17
+ subscribe(listener: IListener<T>): ISubscriptionLike<T> | undefined;
18
+ pipe(): IOrderedSetup<T> | undefined;
19
19
  }
@@ -1,101 +1,101 @@
1
- export declare type ICallback<T> = (value?: T) => any;
2
- export declare type ISubscribe<T> = {
3
- subscribe(listener: IListener<T>): ISubscriptionLike<T>;
1
+ export type ICallback<T> = (value?: T) => any;
2
+ export type ISubscribe<T> = {
3
+ subscribe(listener: IListener<T>): ISubscriptionLike<T> | undefined;
4
4
  };
5
- export declare type IListener<T> = ICallback<T>;
6
- export declare type IDestroy = {
5
+ export type IListener<T> = ICallback<T>;
6
+ export type IDestroy = {
7
7
  destroy(): void;
8
8
  isDestroyed: boolean;
9
9
  };
10
- export declare type IOnceMarker = {
10
+ export type IOnceMarker = {
11
11
  isOnce: boolean;
12
12
  isFinished: boolean;
13
13
  };
14
- export declare type IOrder = {
14
+ export type IOrder = {
15
15
  order: number;
16
16
  };
17
- export declare type IOnce<T> = {
17
+ export type IOnce<T> = {
18
18
  setOnce(): ISubscribe<T>;
19
19
  };
20
- export declare type IOrderedOnce<T> = {
20
+ export type IOrderedOnce<T> = {
21
21
  setOnce(): IOrderedSubscribe<T>;
22
22
  };
23
- export declare type ISetObservableValue = {
23
+ export type ISetObservableValue = {
24
24
  next(value: any): void;
25
25
  };
26
- export declare type ISubscriptionLike<T> = {
26
+ export type ISubscriptionLike<T> = {
27
27
  unsubscribe(): void;
28
28
  };
29
- export declare type ISetup<T> = IUnsubscribeByNegative<T> & IUnsubscribeByPositive<T> & IEmitByNegative<T> & IEmitByPositive<T> & IEmitMatchCondition<T> & IOnce<T> & ISubscribe<T>;
30
- export declare type IOrderedSetup<T> = IOrderedUnsubscribeByNegative<T> & IOrderedUnsubscribeByPositive<T> & IOrderedEmitByNegative<T> & IOrderedEmitByPositive<T> & IOrderedEmitMatchCondition<T> & IOrderedOnce<T> & IOrderedSubscribe<T>;
31
- export declare type ISubscribeObject<T> = ISubscriptionLike<T> & IPause & IOrder & ISend<T> & ISetup<T>;
32
- export declare type ISubscribeCounter = {
29
+ export type ISetup<T> = IUnsubscribeByNegative<T> & IUnsubscribeByPositive<T> & IEmitByNegative<T> & IEmitByPositive<T> & IEmitMatchCondition<T> & IOnce<T> & ISubscribe<T>;
30
+ export type IOrderedSetup<T> = IOrderedUnsubscribeByNegative<T> & IOrderedUnsubscribeByPositive<T> & IOrderedEmitByNegative<T> & IOrderedEmitByPositive<T> & IOrderedEmitMatchCondition<T> & IOrderedOnce<T> & IOrderedSubscribe<T>;
31
+ export type ISubscribeObject<T> = ISubscriptionLike<T> & IPause & IOrder & ISend<T> & ISetup<T>;
32
+ export type ISubscribeCounter = {
33
33
  size(): number;
34
34
  };
35
- export declare type ISubscriber<T> = {
36
- getValue(): T;
35
+ export type ISubscriber<T> = {
36
+ getValue(): T | undefined;
37
37
  isEnable: boolean;
38
38
  } & ISubscribe<T>;
39
- export declare type IObserver<T> = ISetObservableValue & ISubscriber<T> & IDestroy & ISubscribeCounter & IObservablePipe<T> & {
40
- unSubscribe(ISubscriptionLike: any): void;
39
+ export type IObserver<T> = ISetObservableValue & ISubscriber<T> & IDestroy & ISubscribeCounter & IObservablePipe<T> & {
40
+ unSubscribe(subscriber: ISubscriptionLike<T>): void;
41
41
  unsubscribeAll(): void;
42
42
  disable(): void;
43
43
  enable(): void;
44
44
  };
45
- export declare type IPause = {
45
+ export type IPause = {
46
46
  pause(): void;
47
47
  resume(): void;
48
48
  };
49
- export declare type IObservablePipe<T> = {
50
- pipe(): ISetup<T>;
49
+ export type IObservablePipe<T> = {
50
+ pipe(): ISetup<T> | undefined;
51
51
  };
52
- export declare type ISend<T> = {
52
+ export type ISend<T> = {
53
53
  send(value: T): void;
54
54
  };
55
- export declare type IUnsubscribeByNegative<T> = {
55
+ export type IUnsubscribeByNegative<T> = {
56
56
  unsubscribeByNegative(condition: ICallback<any>): ISubscribe<T>;
57
57
  };
58
- export declare type IOrderedUnsubscribeByNegative<T> = {
58
+ export type IOrderedUnsubscribeByNegative<T> = {
59
59
  unsubscribeByNegative(condition: ICallback<any>): IOrderedSubscribe<T>;
60
60
  };
61
- export declare type IUnsubscribeByPositive<T> = {
61
+ export type IUnsubscribeByPositive<T> = {
62
62
  unsubscribeByPositive(condition: ICallback<any>): ISubscribe<T>;
63
63
  };
64
- export declare type IOrderedUnsubscribeByPositive<T> = {
64
+ export type IOrderedUnsubscribeByPositive<T> = {
65
65
  unsubscribeByPositive(condition: ICallback<any>): IOrderedSubscribe<T>;
66
66
  };
67
- export declare type IEmitByNegative<T> = {
67
+ export type IEmitByNegative<T> = {
68
68
  emitByNegative(condition: ICallback<any>): ISubscribe<T>;
69
69
  };
70
- export declare type IOrderedEmitByNegative<T> = {
70
+ export type IOrderedEmitByNegative<T> = {
71
71
  emitByNegative(condition: ICallback<any>): IOrderedSubscribe<T>;
72
72
  };
73
- export declare type IEmitByPositive<T> = {
73
+ export type IEmitByPositive<T> = {
74
74
  emitByPositive(condition: ICallback<any>): ISubscribe<T>;
75
75
  };
76
- export declare type IOrderedEmitByPositive<T> = {
76
+ export type IOrderedEmitByPositive<T> = {
77
77
  emitByPositive(condition: ICallback<any>): IOrderedSubscribe<T>;
78
78
  };
79
- export declare type IEmitMatchCondition<T> = {
79
+ export type IEmitMatchCondition<T> = {
80
80
  emitMatch(condition: ICallback<any>): ISubscribe<T>;
81
81
  };
82
- export declare type IOrderedEmitMatchCondition<T> = {
82
+ export type IOrderedEmitMatchCondition<T> = {
83
83
  emitMatch(condition: ICallback<any>): IOrderedSubscribe<T>;
84
84
  };
85
- export declare type ICollector = IDestroy & ISubscribeCounter & {
85
+ export type ICollector = IDestroy & ISubscribeCounter & {
86
86
  collect(...subscriptionLikeList: ISubscriptionLike<any>[]): void;
87
87
  unsubscribe(subscriptionLike: ISubscriptionLike<any>): void;
88
88
  unsubscribeAll(): void;
89
89
  };
90
- export declare type IOrderedObservable = {
90
+ export type IOrderedObservable = {
91
91
  sortByOrder(): void;
92
92
  };
93
- export declare type IOrdered<T> = IObserver<T> & IOrderedObservable;
94
- export declare type IOrderedSubscriptionLike<T> = ISubscriptionLike<T> & IOrder;
95
- export declare type IOrderedSubscribe<T> = {
93
+ export type IOrdered<T> = IObserver<T> & IOrderedObservable;
94
+ export type IOrderedSubscriptionLike<T> = ISubscriptionLike<T> & IOrder;
95
+ export type IOrderedSubscribe<T> = {
96
96
  subscribe(listener: IListener<T>): IOrderedSubscriptionLike<T>;
97
97
  };
98
- export declare type IGroup = ICollector & {
98
+ export type IGroup = ICollector & {
99
99
  name: string;
100
100
  order: number;
101
101
  };