evg_observable 1.2.34 → 1.4.35

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
@@ -1,3 +1,4 @@
1
+ [![Socket Badge](https://socket.dev/api/badge/npm/package/evg_observable)](https://socket.dev/npm/package/evg_observable)
1
2
  <h1 align=center style="color: saddlebrown">
2
3
  EVG Observable
3
4
  </h1>
@@ -300,20 +301,21 @@ observable$.next('SOME DATA');
300
301
 
301
302
  ### Observable
302
303
 
303
- | method | will return | description |
304
- | :--- | :--- | :--- |
305
- | `.subscribe(listener)` | subscriber | subscribe listener to observable |
304
+ | method | will return | description |
305
+ |:---------------------------| :--- | :--- |
306
+ | `.subscribe(listener)` | subscriber | subscribe listener to observable |
306
307
  | `.unSubscribe(subscriber)` | void | unsubscribe listener from observable |
307
- | `.unsubscribeAll()` | void | unsubscribe all listeners from the current observable |
308
- | `.next(value)` | void | emit data to listeners |
309
- | `.getValue()` | value | will return the last value sent, or the value that was set during initialization |
310
- | `.size()` | number | will return the current number of subscribers |
311
- | `.disable()`| void | disable emission |
312
- | `.enable()`| void | enable emission |
313
- | `.isEnable` | boolean | read-only field that shows the state of the observer |
314
- | `.destroy()` | void | unsubscribe all listeners from the current observable and destroy it |
315
- | `.isDestroyed` | boolean | read-only field that shows the kill state of the observer |
316
- | `.pipe()` | pipe condition object | returns an object with which you can customize the subscriber's behavior |
308
+ | `.unsubscribeAll()` | void | unsubscribe all listeners from the current observable |
309
+ | `.next(value)` | void | emit data to listeners |
310
+ | `.stream(value[])` | void | pass data to listeners in parts of the array |
311
+ | `.getValue()` | value | will return the last value sent, or the value that was set during initialization |
312
+ | `.size()` | number | will return the current number of subscribers |
313
+ | `.disable()` | void | disable emission |
314
+ | `.enable()` | void | enable emission |
315
+ | `.isEnable` | boolean | read-only field that shows the state of the observer |
316
+ | `.destroy()` | void | unsubscribe all listeners from the current observable and destroy it |
317
+ | `.isDestroyed` | boolean | read-only field that shows the kill state of the observer |
318
+ | `.pipe()` | pipe condition object | returns an object with which you can customize the subscriber's behavior |
317
319
 
318
320
  ### Observable`.pipe()`
319
321
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "evg_observable",
3
- "version": "1.2.34",
4
- "description": "Light observable",
3
+ "version": "1.4.35",
4
+ "description": "Alternative fast and light library version - observable.",
5
5
  "directories": {
6
6
  "test": "test"
7
7
  },
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "homepage": "https://github.com/BarushevEA/light-observable-ts#readme",
23
23
  "devDependencies": {
24
- "typescript": "^4.9.4",
24
+ "typescript": "^4.9.5",
25
25
  "@testdeck/mocha": "^0.3.3",
26
26
  "@types/chai": "^4.3.4",
27
27
  "chai": "^4.3.7",
@@ -19,7 +19,7 @@ class Collector {
19
19
  if (this._isDestroyed)
20
20
  return null;
21
21
  subscriptionLike && subscriptionLike.unsubscribe();
22
- FunctionLibs_1.deleteFromArray(this.list, subscriptionLike);
22
+ (0, FunctionLibs_1.deleteFromArray)(this.list, subscriptionLike);
23
23
  }
24
24
  unsubscribeAll() {
25
25
  if (this._isDestroyed)
@@ -1,4 +1,4 @@
1
- import { ICallback, IErrorCallback, IListener, IMarkedForUnsubscribe, IObserver, ISetup, ISubscribe, ISubscribeObject, ISubscriptionLike } from "./Types";
1
+ import { ICallback, IErrorCallback, IListener, IMarkedForUnsubscribe, IObserver, ISetup, IStream, ISubscribe, ISubscribeObject, ISubscriptionLike } from "./Types";
2
2
  export declare class SubscribeObject<T> implements ISubscribeObject<T>, IMarkedForUnsubscribe {
3
3
  isMarkedForUnsubscribe: boolean;
4
4
  protected observable: IObserver<T> | undefined;
@@ -29,7 +29,7 @@ export declare class SubscribeObject<T> implements ISubscribeObject<T>, IMarkedF
29
29
  get order(): number;
30
30
  set order(value: number);
31
31
  }
32
- export declare class Observable<T> implements IObserver<T> {
32
+ export declare class Observable<T> implements IObserver<T>, IStream<T> {
33
33
  private value;
34
34
  protected listeners: ISubscribeObject<T>[];
35
35
  private _isEnable;
@@ -41,6 +41,7 @@ export declare class Observable<T> implements IObserver<T> {
41
41
  enable(): void;
42
42
  get isEnable(): boolean;
43
43
  next(value: T): void;
44
+ stream(values: T[]): void;
44
45
  private handleListenersForUnsubscribe;
45
46
  unSubscribe(listener: ISubscriptionLike<T>): void;
46
47
  destroy(): void;
@@ -41,7 +41,7 @@ class SubscribeObject {
41
41
  subsObj.unsubscribe();
42
42
  break;
43
43
  case !!subsObj.unsubscribeByNegativeCondition:
44
- if (!subsObj.unsubscribeByNegativeCondition()) {
44
+ if (!subsObj.unsubscribeByNegativeCondition(value)) {
45
45
  subsObj.unsubscribeByNegativeCondition = null;
46
46
  subsObj.unsubscribe();
47
47
  return;
@@ -49,7 +49,7 @@ class SubscribeObject {
49
49
  listener(value);
50
50
  break;
51
51
  case !!subsObj.unsubscribeByPositiveCondition:
52
- if (subsObj.unsubscribeByPositiveCondition()) {
52
+ if (subsObj.unsubscribeByPositiveCondition(value)) {
53
53
  subsObj.unsubscribeByPositiveCondition = null;
54
54
  subsObj.unsubscribe();
55
55
  return;
@@ -57,13 +57,13 @@ class SubscribeObject {
57
57
  listener(value);
58
58
  break;
59
59
  case !!subsObj.emitByNegativeCondition:
60
- !subsObj.emitByNegativeCondition() && listener(value);
60
+ !subsObj.emitByNegativeCondition(value) && listener(value);
61
61
  break;
62
62
  case !!subsObj.emitByPositiveCondition:
63
- subsObj.emitByPositiveCondition() && listener(value);
63
+ subsObj.emitByPositiveCondition(value) && listener(value);
64
64
  break;
65
65
  case !!subsObj.emitMatchCondition:
66
- (subsObj.emitMatchCondition() === value) && listener(value);
66
+ (subsObj.emitMatchCondition(value) === value) && listener(value);
67
67
  break;
68
68
  }
69
69
  }
@@ -168,6 +168,15 @@ class Observable {
168
168
  this.isNextProcess = false;
169
169
  this.listenersForUnsubscribe.length && this.handleListenersForUnsubscribe();
170
170
  }
171
+ stream(values) {
172
+ if (this._isDestroyed)
173
+ return;
174
+ if (!this._isEnable)
175
+ return;
176
+ for (let i = 0; i < values.length; i++) {
177
+ this.next(values[i]);
178
+ }
179
+ }
171
180
  handleListenersForUnsubscribe() {
172
181
  const length = this.listenersForUnsubscribe.length;
173
182
  for (let i = 0; i < length; i++) {
@@ -185,7 +194,7 @@ class Observable {
185
194
  marker.isMarkedForUnsubscribe = true;
186
195
  return;
187
196
  }
188
- this.listeners && FunctionLibs_1.deleteFromArray(this.listeners, listener);
197
+ this.listeners && !(0, FunctionLibs_1.deleteFromArray)(this.listeners, listener);
189
198
  }
190
199
  destroy() {
191
200
  this.value = 0;
@@ -46,6 +46,9 @@ export type IObserver<T> = ISetObservableValue & ISubscriber<T> & IDestroy & ISu
46
46
  disable(): void;
47
47
  enable(): void;
48
48
  };
49
+ export type IStream<T> = {
50
+ stream(value: T[]): void;
51
+ };
49
52
  export type IPause = {
50
53
  pause(): void;
51
54
  resume(): void;