evg_observable 1.1.25 → 1.1.27

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.25",
3
+ "version": "1.1.27",
4
4
  "description": "Light observable",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -8,7 +8,7 @@ function deleteFromArray(arr, component) {
8
8
  const length = arr.length - 1;
9
9
  for (let i = index; i < length;)
10
10
  arr[i++] = arr[i];
11
- arr.length--;
11
+ arr.length = length;
12
12
  return true;
13
13
  }
14
14
  exports.deleteFromArray = deleteFromArray;
@@ -1,5 +1,6 @@
1
- import { ICallback, IListener, IObserver, ISetup, ISubscribe, ISubscribeObject, ISubscriptionLike } from "./Types";
2
- export declare class SubscribeObject<T> implements ISubscribeObject<T> {
1
+ import { ICallback, IListener, IMarkedForUnsubscribe, IObserver, ISetup, ISubscribe, ISubscribeObject, ISubscriptionLike } from "./Types";
2
+ export declare class SubscribeObject<T> implements ISubscribeObject<T>, IMarkedForUnsubscribe {
3
+ isMarkedForUnsubscribe: boolean;
3
4
  protected observable: IObserver<T> | undefined;
4
5
  protected listener: IListener<T> | undefined;
5
6
  private isListenPaused;
@@ -4,6 +4,7 @@ exports.Observable = exports.SubscribeObject = void 0;
4
4
  const FunctionLibs_1 = require("./FunctionLibs");
5
5
  class SubscribeObject {
6
6
  constructor(observable, listener) {
7
+ this.isMarkedForUnsubscribe = false;
7
8
  this.isListenPaused = false;
8
9
  this.once = { isOnce: false, isFinished: false };
9
10
  this.unsubscribeByNegativeCondition = null;
@@ -30,7 +31,7 @@ class SubscribeObject {
30
31
  this.sendValueToListener(value);
31
32
  }
32
33
  sendValueToListener(value) {
33
- const asyncSend = () => {
34
+ const asyncSend = (value) => {
34
35
  const listener = this.listener;
35
36
  return new Promise((resolve => {
36
37
  switch (true) {
@@ -76,7 +77,7 @@ class SubscribeObject {
76
77
  resolve(true);
77
78
  }));
78
79
  };
79
- asyncSend()
80
+ asyncSend(value)
80
81
  .catch(err => {
81
82
  console.log('(Unit of SubscribeObject).send(value: T) call .sendValueToListener(value: T) ERROR:', err);
82
83
  });
@@ -170,7 +171,9 @@ class Observable {
170
171
  if (this._isDestroyed)
171
172
  return;
172
173
  if (this.isNextProcess) {
173
- this.listenersForUnsubscribe.push(listener);
174
+ const marker = listener;
175
+ !marker.isMarkedForUnsubscribe && this.listenersForUnsubscribe.push(listener);
176
+ marker.isMarkedForUnsubscribe = true;
174
177
  return;
175
178
  }
176
179
  this.listeners &&
@@ -1,4 +1,7 @@
1
1
  export type ICallback<T> = (value?: T) => any;
2
+ export type IMarkedForUnsubscribe = {
3
+ isMarkedForUnsubscribe: boolean;
4
+ };
2
5
  export type ISubscribe<T> = {
3
6
  subscribe(listener: IListener<T>): ISubscriptionLike<T> | undefined;
4
7
  };