evg_observable 1.4.36 → 1.4.38
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 +1 -1
- package/repo/evg_observable.js +1 -0
- package/src/outLib/Collector.d.ts +2 -2
- package/src/outLib/Collector.js +7 -11
- package/src/outLib/FunctionLibs.d.ts +1 -0
- package/src/outLib/FunctionLibs.js +11 -5
- package/src/outLib/Observable.d.ts +2 -2
- package/src/outLib/Observable.js +1 -1
- package/src/outLib/OrderedObservable.d.ts +2 -1
- package/src/outLib/OrderedObservable.js +12 -0
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{"use strict";var e={909:(e,s,i)=>{s.P=void 0;const t=i(594);s.P=class{constructor(){this.list=[],this._isDestroyed=!1}collect(...e){this._isDestroyed||this.list.push(...e)}unsubscribe(e){this._isDestroyed||(null==e||e.unsubscribe(),(0,t.quickDeleteFromArray)(this.list,e))}unsubscribeAll(){if(!this._isDestroyed)for(;this.list.length>0;)this.unsubscribe(this.list.pop())}size(){return this._isDestroyed?0:this.list.length}destroy(){this.unsubscribeAll(),this.list.length=0,this.list=0,this._isDestroyed=!0}get isDestroyed(){return this._isDestroyed}}},594:(e,s)=>{Object.defineProperty(s,"__esModule",{value:!0}),s.positiveCallback=s.negativeCallback=s.quickDeleteFromArray=s.deleteFromArray=void 0,s.deleteFromArray=function(e,s){const i=e.indexOf(s);return-1!==i&&(e.splice(i,1),!0)},s.quickDeleteFromArray=function(e,s){const i=e.indexOf(s);return-1!==i&&(e[i]=e[e.length-1],e.length=e.length-1,!0)},s.negativeCallback=()=>!1,s.positiveCallback=()=>!0},637:(e,s,i)=>{Object.defineProperty(s,"__esModule",{value:!0}),s.Observable=s.SubscribeObject=void 0;const t=i(594);class r{constructor(e,s){this.isMarkedForUnsubscribe=!1,this.errorHandler=(e,s)=>{console.log(`(Unit of SubscribeObject).send(${e}) ERROR:`,s)},this._order=0,this.isListenPaused=!1,this.once={isOnce:!1,isFinished:!1},this.unsubscribeByNegativeCondition=null,this.unsubscribeByPositiveCondition=null,this.emitByNegativeCondition=null,this.emitByPositiveCondition=null,this.emitMatchCondition=null,this.isPipe=!1,this.observable=e,this.isPipe=!!s}static callbackSend(e,s){const i=s.listener;if(i)switch(!0){case!s.observable:return void s.unsubscribe();case s.isListenPaused:return;case!s.isPipe:return void i(e);case s.once.isOnce:s.once.isFinished=!0,i(e),s.unsubscribe();break;case!!s.unsubscribeByNegativeCondition:if(!s.unsubscribeByNegativeCondition(e))return s.unsubscribeByNegativeCondition=null,void s.unsubscribe();i(e);break;case!!s.unsubscribeByPositiveCondition:if(s.unsubscribeByPositiveCondition(e))return s.unsubscribeByPositiveCondition=null,void s.unsubscribe();i(e);break;case!!s.emitByNegativeCondition:!s.emitByNegativeCondition(e)&&i(e);break;case!!s.emitByPositiveCondition:s.emitByPositiveCondition(e)&&i(e);break;case!!s.emitMatchCondition:s.emitMatchCondition(e)===e&&i(e)}else s.unsubscribe()}subscribe(e,s){return this.listener=e,s&&(this.errorHandler=s),this}unsubscribe(){this.observable&&(this.observable.unSubscribe(this),this.observable=0,this.listener=0)}send(e){try{r.callbackSend(e,this)}catch(s){this.errorHandler(e,s)}}setOnce(){return this.once.isOnce=!0,this}unsubscribeByNegative(e){return this.unsubscribeByNegativeCondition=e||t.negativeCallback,this}unsubscribeByPositive(e){return this.unsubscribeByPositiveCondition=e||t.positiveCallback,this}emitByNegative(e){return this.emitByNegativeCondition=e||t.positiveCallback,this}emitByPositive(e){return this.emitByPositiveCondition=e||t.negativeCallback,this}emitMatch(e){const s=typeof e;return"function"!==s&&(e=()=>`ERROR CONDITION TYPE ${s}, CONTROL STATE ${this.observable&&!this.observable.getValue()}`),this.emitMatchCondition=e,this}resume(){this.isListenPaused=!1}pause(){this.isListenPaused=!0}get order(){return this._order}set order(e){this._order=e}}s.SubscribeObject=r,s.Observable=class{constructor(e){this.value=e,this.listeners=[],this._isEnable=!0,this._isDestroyed=!1,this.isNextProcess=!1,this.listenersForUnsubscribe=[]}disable(){this._isEnable=!1}enable(){this._isEnable=!0}get isEnable(){return this._isEnable}next(e){if(this._isDestroyed)return;if(!this._isEnable)return;this.isNextProcess=!0,this.value=e;const s=this.listeners.length;for(let i=0;i<s;i++)this.listeners[i].send(e);this.isNextProcess=!1,this.listenersForUnsubscribe.length&&this.handleListenersForUnsubscribe()}stream(e){if(!this._isDestroyed&&this._isEnable)for(let s=0;s<e.length;s++)this.next(e[s])}handleListenersForUnsubscribe(){const e=this.listenersForUnsubscribe.length;for(let s=0;s<e;s++){const e=this.listenersForUnsubscribe[s];this.unSubscribe(e)}this.listenersForUnsubscribe.length=0}unSubscribe(e){if(!this._isDestroyed){if(this.isNextProcess&&e){const s=e;return!s.isMarkedForUnsubscribe&&this.listenersForUnsubscribe.push(e),void(s.isMarkedForUnsubscribe=!0)}this.listeners&&(0,t.quickDeleteFromArray)(this.listeners,e)}}destroy(){this.value=0,this.unsubscribeAll(),this.listeners=0,this._isDestroyed=!0}unsubscribeAll(){this._isDestroyed||(this.listeners.length=0)}getValue(){if(!this._isDestroyed)return this.value}size(){return this._isDestroyed?0:this.listeners.length}subscribe(e,s){if(this._isDestroyed)return;if(!e)return;const i=new r(this,!1);return i.subscribe(e,s),this.listeners.push(i),i}pipe(){if(this._isDestroyed)return;const e=new r(this,!0);return this.listeners.push(e),e}get isDestroyed(){return this._isDestroyed}}},546:(e,s,i)=>{s.Nc=void 0;const t=i(637),r=i(594);class n extends t.SubscribeObject{constructor(e,s){super(e,s)}get order(){return this._order}set order(e){!this.observable||this.observable&&this.observable.isDestroyed?this._order=void 0:(this._order=e,this.observable.sortByOrder())}subscribe(e,s){return this.listener=e,s&&(this.errorHandler=s),this}setOnce(){return super.setOnce()}unsubscribeByNegative(e){return super.unsubscribeByNegative(e)}unsubscribeByPositive(e){return super.unsubscribeByPositive(e)}emitByNegative(e){return super.emitByNegative(e)}emitByPositive(e){return super.emitByPositive(e)}emitMatch(e){return super.emitMatch(e)}}class o extends t.Observable{sortByOrder(){return!this._isDestroyed&&(this.listeners.sort(((e,s)=>e.order>s.order?1:e.order<s.order?-1:0)),!0)}subscribe(e,s){if(this._isDestroyed)return;if(!e)return;const i=new n(this,!1);return i.subscribe(e,s),this.listeners.push(i),i}pipe(){if(this._isDestroyed)return;const e=new n(this,!0);return this.listeners.push(e),e}unSubscribe(e){if(!this._isDestroyed){if(this.isNextProcess&&e){const s=e;return!s.isMarkedForUnsubscribe&&this.listenersForUnsubscribe.push(e),void(s.isMarkedForUnsubscribe=!0)}this.listeners&&(0,r.deleteFromArray)(this.listeners,e)}}}s.Nc=o}},s={};function i(t){var r=s[t];if(void 0!==r)return r.exports;var n=s[t]={exports:{}};return e[t](n,n.exports,i),n.exports}(()=>{var e=i(637),s=i(909),t=i(546);const r=window;r.Observable=e.Observable,r.Collector=s.P,r.OrderedObservable=t.Nc})()})();
|
|
@@ -2,8 +2,8 @@ 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> | undefined): void
|
|
5
|
+
collect(...subscriptionLikeList: ISubscriptionLike<any>[]): void;
|
|
6
|
+
unsubscribe(subscriptionLike: ISubscriptionLike<any> | undefined): void;
|
|
7
7
|
unsubscribeAll(): void | null;
|
|
8
8
|
size(): number;
|
|
9
9
|
destroy(): void;
|
package/src/outLib/Collector.js
CHANGED
|
@@ -8,24 +8,20 @@ class Collector {
|
|
|
8
8
|
this._isDestroyed = false;
|
|
9
9
|
}
|
|
10
10
|
collect(...subscriptionLikeList) {
|
|
11
|
-
if (this._isDestroyed)
|
|
12
|
-
|
|
13
|
-
for (let i = 0; i < subscriptionLikeList.length; i++) {
|
|
14
|
-
const subscription = subscriptionLikeList[i];
|
|
15
|
-
subscription && this.list.push(subscription);
|
|
11
|
+
if (!this._isDestroyed) {
|
|
12
|
+
this.list.push(...subscriptionLikeList);
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
15
|
unsubscribe(subscriptionLike) {
|
|
19
16
|
if (this._isDestroyed)
|
|
20
|
-
return
|
|
21
|
-
subscriptionLike
|
|
22
|
-
(0, FunctionLibs_1.
|
|
17
|
+
return;
|
|
18
|
+
subscriptionLike === null || subscriptionLike === void 0 ? void 0 : subscriptionLike.unsubscribe();
|
|
19
|
+
(0, FunctionLibs_1.quickDeleteFromArray)(this.list, subscriptionLike);
|
|
23
20
|
}
|
|
24
21
|
unsubscribeAll() {
|
|
25
22
|
if (this._isDestroyed)
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
for (let i = 0; i < length; i++) {
|
|
23
|
+
return;
|
|
24
|
+
while (this.list.length > 0) {
|
|
29
25
|
this.unsubscribe(this.list.pop());
|
|
30
26
|
}
|
|
31
27
|
}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.positiveCallback = exports.negativeCallback = exports.deleteFromArray = void 0;
|
|
3
|
+
exports.positiveCallback = exports.negativeCallback = exports.quickDeleteFromArray = exports.deleteFromArray = void 0;
|
|
4
4
|
function deleteFromArray(arr, component) {
|
|
5
5
|
const index = arr.indexOf(component);
|
|
6
6
|
if (index === -1)
|
|
7
7
|
return false;
|
|
8
|
-
|
|
9
|
-
for (let i = index; i < length;)
|
|
10
|
-
arr[i++] = arr[i];
|
|
11
|
-
arr.length = length;
|
|
8
|
+
arr.splice(index, 1);
|
|
12
9
|
return true;
|
|
13
10
|
}
|
|
14
11
|
exports.deleteFromArray = deleteFromArray;
|
|
12
|
+
function quickDeleteFromArray(arr, component) {
|
|
13
|
+
const index = arr.indexOf(component);
|
|
14
|
+
if (index === -1)
|
|
15
|
+
return false;
|
|
16
|
+
arr[index] = arr[arr.length - 1];
|
|
17
|
+
arr.length = arr.length - 1;
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
exports.quickDeleteFromArray = quickDeleteFromArray;
|
|
15
21
|
const negativeCallback = () => false;
|
|
16
22
|
exports.negativeCallback = negativeCallback;
|
|
17
23
|
const positiveCallback = () => true;
|
|
@@ -34,8 +34,8 @@ export declare class Observable<T> implements IObserver<T>, IStream<T> {
|
|
|
34
34
|
protected listeners: ISubscribeObject<T>[];
|
|
35
35
|
private _isEnable;
|
|
36
36
|
protected _isDestroyed: boolean;
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
protected isNextProcess: boolean;
|
|
38
|
+
protected listenersForUnsubscribe: ISubscriptionLike<T>[];
|
|
39
39
|
constructor(value: T);
|
|
40
40
|
disable(): void;
|
|
41
41
|
enable(): void;
|
package/src/outLib/Observable.js
CHANGED
|
@@ -187,7 +187,7 @@ class Observable {
|
|
|
187
187
|
marker.isMarkedForUnsubscribe = true;
|
|
188
188
|
return;
|
|
189
189
|
}
|
|
190
|
-
this.listeners && !(0, FunctionLibs_1.
|
|
190
|
+
this.listeners && !(0, FunctionLibs_1.quickDeleteFromArray)(this.listeners, listener);
|
|
191
191
|
}
|
|
192
192
|
destroy() {
|
|
193
193
|
this.value = 0;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable, SubscribeObject } from "./Observable";
|
|
2
|
-
import { ICallback, IErrorCallback, IListener, IOrdered, IOrderedSetup, IOrderedSubscribe, IOrderedSubscriptionLike } from "./Types";
|
|
2
|
+
import { ICallback, IErrorCallback, 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>, isPipe?: boolean);
|
|
5
5
|
get order(): number;
|
|
@@ -16,4 +16,5 @@ export declare class OrderedObservable<T> extends Observable<T> implements IOrde
|
|
|
16
16
|
sortByOrder(): boolean;
|
|
17
17
|
subscribe(listener: IListener<T>, errorHandler?: IErrorCallback): IOrderedSubscriptionLike<T> | undefined;
|
|
18
18
|
pipe(): IOrderedSetup<T> | undefined;
|
|
19
|
+
unSubscribe(listener: ISubscriptionLike<T>): void;
|
|
19
20
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OrderedObservable = exports.OrderedSubscribeObject = void 0;
|
|
4
4
|
const Observable_1 = require("./Observable");
|
|
5
|
+
const FunctionLibs_1 = require("./FunctionLibs");
|
|
5
6
|
class OrderedSubscribeObject extends Observable_1.SubscribeObject {
|
|
6
7
|
constructor(observable, isPipe) {
|
|
7
8
|
super(observable, isPipe);
|
|
@@ -73,5 +74,16 @@ class OrderedObservable extends Observable_1.Observable {
|
|
|
73
74
|
this.listeners.push(subscribeObject);
|
|
74
75
|
return subscribeObject;
|
|
75
76
|
}
|
|
77
|
+
unSubscribe(listener) {
|
|
78
|
+
if (this._isDestroyed)
|
|
79
|
+
return;
|
|
80
|
+
if (this.isNextProcess && listener) {
|
|
81
|
+
const marker = listener;
|
|
82
|
+
!marker.isMarkedForUnsubscribe && this.listenersForUnsubscribe.push(listener);
|
|
83
|
+
marker.isMarkedForUnsubscribe = true;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.listeners && !(0, FunctionLibs_1.deleteFromArray)(this.listeners, listener);
|
|
87
|
+
}
|
|
76
88
|
}
|
|
77
89
|
exports.OrderedObservable = OrderedObservable;
|