evg_observable 3.0.1 → 3.1.1
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/.claudeignore +9 -0
- package/README.md +298 -21
- package/package.json +42 -18
- package/repo/evg_observable.js +1 -1
- package/repo/evg_observable.old.js +1 -0
- package/scripts/README.md +69 -0
- package/scripts/claude-full-check.sh +33 -0
- package/scripts/claude-pr-prep.sh +73 -0
- package/scripts/claude-review-files.sh +61 -0
- package/src/outLib/CoreTypes.d.ts +42 -0
- package/src/outLib/CoreTypes.js +2 -0
- package/src/outLib/FilterCollection.js +2 -1
- package/src/outLib/FilterTypes.d.ts +27 -0
- package/src/outLib/FilterTypes.js +2 -0
- package/src/outLib/FunctionLibs.js +5 -4
- package/src/outLib/Observable.d.ts +2 -1
- package/src/outLib/Observable.js +14 -5
- package/src/outLib/OrderedSubscribeObject.d.ts +3 -0
- package/src/outLib/OrderedSubscribeObject.js +9 -0
- package/src/outLib/Pipe.d.ts +8 -1
- package/src/outLib/Pipe.js +123 -3
- package/src/outLib/PipeTypes.d.ts +77 -0
- package/src/outLib/PipeTypes.js +2 -0
- package/src/outLib/SubscribeObject.js +19 -42
- package/src/outLib/SubscriptionTypes.d.ts +40 -0
- package/src/outLib/SubscriptionTypes.js +2 -0
- package/src/outLib/Types.d.ts +4 -178
- package/src/outLib/Types.js +18 -0
- package/src/outLib-esm/index.mjs +1 -0
|
@@ -50,9 +50,10 @@ class SubscribeObject extends Pipe_1.Pipe {
|
|
|
50
50
|
unsubscribe() {
|
|
51
51
|
if (!this.observer)
|
|
52
52
|
return;
|
|
53
|
+
clearTimeout(this.flow.debounceTimer);
|
|
53
54
|
this.observer.unSubscribe(this);
|
|
54
|
-
this.observer =
|
|
55
|
-
this.listener =
|
|
55
|
+
this.observer = undefined;
|
|
56
|
+
this.listener = undefined;
|
|
56
57
|
this.chain.length = 0;
|
|
57
58
|
}
|
|
58
59
|
send(value) {
|
|
@@ -73,53 +74,29 @@ class SubscribeObject extends Pipe_1.Pipe {
|
|
|
73
74
|
this.errorHandler(value, err);
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
|
-
if (hasGroupListeners) {
|
|
77
|
-
for (let i = 0; i < this.listeners.length; i++) {
|
|
78
|
-
try {
|
|
79
|
-
this.listeners[i](value);
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
this.errorHandlers[i](value, err);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
77
|
return;
|
|
87
78
|
}
|
|
88
79
|
try {
|
|
89
80
|
this.flow.payload = value;
|
|
90
81
|
this.flow.isBreak = false;
|
|
91
|
-
if (listener) {
|
|
92
|
-
this.processChain(listener);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
const chain = this.chain;
|
|
96
|
-
const data = this.flow;
|
|
97
|
-
const len = chain.length;
|
|
98
|
-
data.isAvailable = len === 0;
|
|
99
|
-
for (let i = 0; i < len; i++) {
|
|
100
|
-
data.isUnsubscribe = false;
|
|
101
|
-
data.isAvailable = false;
|
|
102
|
-
chain[i](data);
|
|
103
|
-
if (data.isUnsubscribe) {
|
|
104
|
-
this.unsubscribe();
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (!data.isAvailable)
|
|
108
|
-
return;
|
|
109
|
-
if (data.isBreak)
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
82
|
if (hasGroupListeners) {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
83
|
+
const groupListeners = this.listeners;
|
|
84
|
+
const groupErrorHandlers = this.errorHandlers;
|
|
85
|
+
this.processChain((value) => {
|
|
86
|
+
if (listener)
|
|
87
|
+
listener(value);
|
|
88
|
+
for (let i = 0; i < groupListeners.length; i++) {
|
|
89
|
+
try {
|
|
90
|
+
groupListeners[i](value);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
groupErrorHandlers[i](value, err);
|
|
94
|
+
}
|
|
121
95
|
}
|
|
122
|
-
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
this.processChain(listener);
|
|
123
100
|
}
|
|
124
101
|
}
|
|
125
102
|
catch (err) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IDestroy, IErrorCallback, IListener, IOrder, ISetObservableValue, ISubscribeCounter, ISubscribeGroup } from "./CoreTypes";
|
|
2
|
+
import type { ISetup } from "./PipeTypes";
|
|
3
|
+
export type ISubscriptionLike = {
|
|
4
|
+
unsubscribe(): void;
|
|
5
|
+
};
|
|
6
|
+
export type IGroupSubscription<T> = ISubscriptionLike & {
|
|
7
|
+
add(listener: IListener<T> | IListener<T>[], errorHandler?: IErrorCallback | IErrorCallback[]): IGroupSubscription<T>;
|
|
8
|
+
};
|
|
9
|
+
export type ISubscribe<T> = {
|
|
10
|
+
subscribe(listener: ISubscribeGroup<T>, errorHandler?: IErrorCallback): ISubscriptionLike | undefined;
|
|
11
|
+
};
|
|
12
|
+
export type IOrderedSubscribe<T> = {
|
|
13
|
+
subscribe(listener: IListener<T>, errorHandler?: IErrorCallback): IOrderedSubscriptionLike;
|
|
14
|
+
};
|
|
15
|
+
export type ISubscriber<T> = {
|
|
16
|
+
getValue(): T | undefined;
|
|
17
|
+
isEnable: boolean;
|
|
18
|
+
} & ISubscribe<T>;
|
|
19
|
+
export type IOrderedSubscriptionLike = (ISubscriptionLike & IOrder);
|
|
20
|
+
export type IObservablePipe<T> = {
|
|
21
|
+
pipe(): ISetup<T> | undefined;
|
|
22
|
+
};
|
|
23
|
+
export type IOrderedObservablePipe<T> = {
|
|
24
|
+
pipe(): ISetup<T> | undefined;
|
|
25
|
+
};
|
|
26
|
+
export type IObserver<T> = ISetObservableValue & ISubscriber<T> & IDestroy & ISubscribeCounter & IObservablePipe<T> & {
|
|
27
|
+
unSubscribe(subscriber: ISubscriptionLike): void;
|
|
28
|
+
unsubscribeAll(): void;
|
|
29
|
+
disable(): void;
|
|
30
|
+
enable(): void;
|
|
31
|
+
};
|
|
32
|
+
export type IOrderedObservable = {
|
|
33
|
+
sortByOrder(): boolean;
|
|
34
|
+
};
|
|
35
|
+
export type IOrdered<T> = IObserver<T> & IOrderedObservable & IOrderedObservablePipe<T>;
|
|
36
|
+
export type ICollector = IDestroy & ISubscribeCounter & {
|
|
37
|
+
collect(...subscriptionLikeList: ISubscriptionLike[]): void;
|
|
38
|
+
unsubscribe(subscriptionLike: ISubscriptionLike): void;
|
|
39
|
+
unsubscribeAll(): void;
|
|
40
|
+
};
|
package/src/outLib/Types.d.ts
CHANGED
|
@@ -1,178 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export type ISubscribe<T> = {
|
|
6
|
-
subscribe(listener: ISubscribeGroup<T>, errorHandler?: IErrorCallback): ISubscriptionLike | undefined;
|
|
7
|
-
};
|
|
8
|
-
export type IListener<T> = ICallback<T>;
|
|
9
|
-
export type IDestroy = {
|
|
10
|
-
destroy(): void;
|
|
11
|
-
isDestroyed: boolean;
|
|
12
|
-
};
|
|
13
|
-
export type IOrder = {
|
|
14
|
-
order: number;
|
|
15
|
-
};
|
|
16
|
-
export type ISwitch<T> = {
|
|
17
|
-
choice(): PipeSwitchCase<T>;
|
|
18
|
-
};
|
|
19
|
-
export type IOrderedSwitch<T> = {
|
|
20
|
-
choice(): PipeSwitchCase<T>;
|
|
21
|
-
};
|
|
22
|
-
export type IGroup<T> = {
|
|
23
|
-
group(): IGroupSubscription<T>;
|
|
24
|
-
};
|
|
25
|
-
export type IOrderedGroup<T> = {
|
|
26
|
-
group(): IGroupSubscription<T>;
|
|
27
|
-
};
|
|
28
|
-
export type IOnce<T> = {
|
|
29
|
-
once(): ISubscribe<T>;
|
|
30
|
-
};
|
|
31
|
-
export type IOrderedOnce<T> = {
|
|
32
|
-
once(): IOrderedSubscribe<T>;
|
|
33
|
-
};
|
|
34
|
-
export type ISetObservableValue = {
|
|
35
|
-
next(value: any): void;
|
|
36
|
-
};
|
|
37
|
-
export type ISubscriptionLike = {
|
|
38
|
-
unsubscribe(): void;
|
|
39
|
-
};
|
|
40
|
-
export type IGroupSubscription<T> = ISubscriptionLike & {
|
|
41
|
-
add(listener: IListener<T> | IListener<T>[], errorHandler?: IErrorCallback | IErrorCallback[]): IGroupSubscription<T>;
|
|
42
|
-
};
|
|
43
|
-
export type ISetup<T> = IUnsubscribeByPositive<T> & IEmitByPositive<T> & IOnce<T> & ISwitch<T> & ITransform<T> & ISerialisation & IGroup<T> & ISubscribe<T>;
|
|
44
|
-
export type IOrderedSetup<T> = IOrderedUnsubscribeByPositive<T> & IOrderedEmitByPositive<T> & IOrderedOnce<T> & IOrderedSwitch<T> & IOrderedTransform<T> & IOrderedSerialisation & IOrderedGroup<T> & IOrderedSubscribe<T>;
|
|
45
|
-
export type ISubscribeObject<T> = ISubscriptionLike & IPause & IOrder & ISend<T> & ISetup<T>;
|
|
46
|
-
export type ISubscribeCounter = {
|
|
47
|
-
size(): number;
|
|
48
|
-
};
|
|
49
|
-
export type ISubscriber<T> = {
|
|
50
|
-
getValue(): T | undefined;
|
|
51
|
-
isEnable: boolean;
|
|
52
|
-
} & ISubscribe<T>;
|
|
53
|
-
export type IObserver<T> = ISetObservableValue & ISubscriber<T> & IDestroy & ISubscribeCounter & IObservablePipe<T> & {
|
|
54
|
-
unSubscribe(subscriber: ISubscriptionLike): void;
|
|
55
|
-
unsubscribeAll(): void;
|
|
56
|
-
disable(): void;
|
|
57
|
-
enable(): void;
|
|
58
|
-
};
|
|
59
|
-
export type IStream<T> = {
|
|
60
|
-
of(value: T[]): void;
|
|
61
|
-
};
|
|
62
|
-
export type IObjectStream<K extends string | number | symbol, V> = {
|
|
63
|
-
in(value: Record<K, V>): void;
|
|
64
|
-
};
|
|
65
|
-
export type IPause = {
|
|
66
|
-
pause(): void;
|
|
67
|
-
resume(): void;
|
|
68
|
-
};
|
|
69
|
-
export type IObservablePipe<T> = {
|
|
70
|
-
pipe(): ISetup<T> | undefined;
|
|
71
|
-
};
|
|
72
|
-
export type IOrderedObservablePipe<T> = {
|
|
73
|
-
pipe(): ISetup<T> | undefined;
|
|
74
|
-
};
|
|
75
|
-
export type ISend<T> = {
|
|
76
|
-
send(value: T): void;
|
|
77
|
-
};
|
|
78
|
-
export type IUnsubscribeByNegative<T> = {
|
|
79
|
-
unsubscribeByNegative(condition: ICallback<T>): ISetup<T>;
|
|
80
|
-
};
|
|
81
|
-
export type IOrderedUnsubscribeByNegative<T> = {
|
|
82
|
-
unsubscribeByNegative(condition: ICallback<T>): IOrderedSetup<T>;
|
|
83
|
-
};
|
|
84
|
-
export type IUnsubscribeByPositive<T> = {
|
|
85
|
-
unsubscribeBy(condition: ICallback<T>): ISetup<T>;
|
|
86
|
-
};
|
|
87
|
-
export type IOrderedUnsubscribeByPositive<T> = {
|
|
88
|
-
unsubscribeBy(condition: ICallback<T>): ISetup<T>;
|
|
89
|
-
};
|
|
90
|
-
export type IEmitByNegative<T> = {
|
|
91
|
-
emitByNegative(condition: ICallback<T>): ISetup<T>;
|
|
92
|
-
};
|
|
93
|
-
export type IOrderedEmitByNegative<T> = {
|
|
94
|
-
emitByNegative(condition: ICallback<T>): IOrderedSetup<T>;
|
|
95
|
-
};
|
|
96
|
-
export type IEmitByPositive<T> = {
|
|
97
|
-
and(condition: ICallback<T>): ISetup<T>;
|
|
98
|
-
allOf(conditions: ICallback<T>[]): ISetup<T>;
|
|
99
|
-
};
|
|
100
|
-
export type ITransform<T> = {
|
|
101
|
-
map<K>(condition: ICallback<T>): ISetup<K>;
|
|
102
|
-
};
|
|
103
|
-
export type ISerialisation = {
|
|
104
|
-
toJson(): ISetup<string>;
|
|
105
|
-
fromJson<K>(): ISetup<K>;
|
|
106
|
-
};
|
|
107
|
-
export type IOrderedEmitByPositive<T> = {
|
|
108
|
-
and(condition: ICallback<any>): ISetup<T>;
|
|
109
|
-
allOf(conditions: ICallback<any>[]): ISetup<T>;
|
|
110
|
-
};
|
|
111
|
-
export type IOrderedTransform<T> = {
|
|
112
|
-
map<K>(condition: ICallback<T>): ISetup<K>;
|
|
113
|
-
};
|
|
114
|
-
export type IOrderedSerialisation = {
|
|
115
|
-
toJson(): ISetup<string>;
|
|
116
|
-
fromJson<K>(): ISetup<K>;
|
|
117
|
-
};
|
|
118
|
-
export type IEmitMatchCondition<T> = {
|
|
119
|
-
emitMatch(condition: ICallback<any>): ISetup<T>;
|
|
120
|
-
};
|
|
121
|
-
export type IOrderedEmitMatchCondition<T> = {
|
|
122
|
-
emitMatch(condition: ICallback<any>): IOrderedSetup<T>;
|
|
123
|
-
};
|
|
124
|
-
export type ICollector = IDestroy & ISubscribeCounter & {
|
|
125
|
-
collect(...subscriptionLikeList: ISubscriptionLike[]): void;
|
|
126
|
-
unsubscribe(subscriptionLike: ISubscriptionLike): void;
|
|
127
|
-
unsubscribeAll(): void;
|
|
128
|
-
};
|
|
129
|
-
export type IOrderedObservable = {
|
|
130
|
-
sortByOrder(): boolean;
|
|
131
|
-
};
|
|
132
|
-
export type IOrdered<T> = IObserver<T> & IOrderedObservable & IOrderedObservablePipe<T>;
|
|
133
|
-
export type IOrderedSubscriptionLike = (ISubscriptionLike & IOrder);
|
|
134
|
-
export type IOrderedSubscribe<T> = {
|
|
135
|
-
subscribe(listener: IListener<T>, errorHandler?: IErrorCallback): IOrderedSubscriptionLike;
|
|
136
|
-
};
|
|
137
|
-
export type IChainContainer = {
|
|
138
|
-
chain: any[];
|
|
139
|
-
};
|
|
140
|
-
export type IPipePayload = {
|
|
141
|
-
isBreak: boolean;
|
|
142
|
-
isUnsubscribe: boolean;
|
|
143
|
-
isAvailable: boolean;
|
|
144
|
-
payload: any;
|
|
145
|
-
};
|
|
146
|
-
export type IChainCallback = (data: IPipePayload) => void;
|
|
147
|
-
export type IPipeCase<T> = ISubscribe<T> & {
|
|
148
|
-
or(condition: ICallback<any>): IPipeCase<T> & ISubscribe<T>;
|
|
149
|
-
anyOf(conditions: ICallback<any>[]): IPipeCase<T> & ISubscribe<T>;
|
|
150
|
-
group(): IGroupSubscription<T>;
|
|
151
|
-
};
|
|
152
|
-
export type ICombinedSubscriber<T> = IListener<T> | ISetObservableValue;
|
|
153
|
-
export type ISubscribeGroup<T> = ICombinedSubscriber<T> | ICombinedSubscriber<T>[];
|
|
154
|
-
export type IAddFilter<T> = {
|
|
155
|
-
addFilter(): IFilterSetup<T>;
|
|
156
|
-
};
|
|
157
|
-
export type IFilterSetup<T> = IFilter<T> & IFilterSwitch<T>;
|
|
158
|
-
export type IFilter<T> = {
|
|
159
|
-
and(condition: ICallback<any>): IFilterSetup<T>;
|
|
160
|
-
allOf(conditions: ICallback<any>[]): IFilterSetup<T>;
|
|
161
|
-
};
|
|
162
|
-
export type IFilterSwitch<T> = {
|
|
163
|
-
choice(): FilterSwitchCase<T>;
|
|
164
|
-
};
|
|
165
|
-
export type IFilterCase<T> = {
|
|
166
|
-
or(condition: ICallback<any>): IFilterCase<T>;
|
|
167
|
-
anyOf(conditions: ICallback<any>[]): IFilterCase<T>;
|
|
168
|
-
};
|
|
169
|
-
export type IFilterPayload = {
|
|
170
|
-
isBreak: boolean;
|
|
171
|
-
isAvailable: boolean;
|
|
172
|
-
payload: any;
|
|
173
|
-
};
|
|
174
|
-
export type IFilterChainCallback = (data: IFilterPayload) => void;
|
|
175
|
-
export type IFilterResponse = {
|
|
176
|
-
isOK: boolean;
|
|
177
|
-
payload: any;
|
|
178
|
-
};
|
|
1
|
+
export * from './CoreTypes';
|
|
2
|
+
export * from './SubscriptionTypes';
|
|
3
|
+
export * from './PipeTypes';
|
|
4
|
+
export * from './FilterTypes';
|
package/src/outLib/Types.js
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./CoreTypes"), exports);
|
|
18
|
+
__exportStar(require("./SubscriptionTypes"), exports);
|
|
19
|
+
__exportStar(require("./PipeTypes"), exports);
|
|
20
|
+
__exportStar(require("./FilterTypes"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function I(t,e){return t.order>e.order?1:t.order<e.order?-1:0}function k(t,e){return t.order>e.order?-1:t.order<e.order?1:0}function u(t,e){let r=t.indexOf(e);return r===-1?!1:(t.splice(r,1),!0)}function C(t,e){let r=t.indexOf(e);return r===-1?!1:(t[r]=t[t.length-1],t.length--,!0)}function v(t){if(Array.isArray(t)){let e=t.length,r=new Array(e);for(let i=0;i<e;i++)r[i]=S(t[i]);return i=>{for(let s=0;s<e;s++)r[s](i)}}return S(t)}function S(t){return"next"in t?e=>t.next(e):t}var b=class{pipe;counter;constructor(e){this.pipe=e,this.counter=e.chain.length?e.chain.length:0}or(e){this.counter++;let r=this.counter,i=this.pipe.chain;return i.push(s=>{s.isAvailable=!0,e(s.payload)&&(s.isBreak=!0),r===i.length&&!s.isBreak&&(s.isAvailable=!1)}),this}anyOf(e){if(!Array.isArray(e))return this;for(let r=0;r<e.length;r++)this.or(e[r]);return this}};var h=class{chain=[];flow={isBreak:!1,isUnsubscribe:!1,isAvailable:!1,debounceMs:0,debounceTimer:0,debounceValue:void 0,debounceIndex:0,payload:null};push(e){return this.chain.push(e),this}once(){return this.push(e=>{this.listener(e.payload),e.isUnsubscribe=!0})}take(e){e<0&&(e=0);let r=0;return this.push(i=>{if(r>=e){i.isUnsubscribe=!0;return}r++,this.listener(i.payload),r>=e&&(i.isUnsubscribe=!0)})}skip(e){e<0&&(e=0);let r=0;return this.push(i=>{if(r<e){r++;return}i.isAvailable=!0})}unsubscribeBy(e){return this.push(r=>{r.isAvailable=!0,e(r.payload)&&(r.isUnsubscribe=!0)})}and(e){return this.push(r=>{e(r.payload)&&(r.isAvailable=!0)})}allOf(e){if(!Array.isArray(e))return this;for(let r=0;r<e.length;r++)this.and(e[r]);return this}choice(){return new f(this)}map(e){return this.push(r=>{r.payload=e(r.payload),r.isAvailable=!0})}scan(e,r){let i=r;return this.push(s=>{i=e(i,s.payload),s.payload=i,s.isAvailable=!0})}tap(e){return this.push(r=>{e(r.payload),r.isAvailable=!0})}throttle(e){let r=0;return this.push(i=>{let s=Date.now();s-r>=e&&(r=s,i.isAvailable=!0)})}debounce(e){return this.push(r=>{r.isAvailable=!0,r.debounceMs=e})}distinctUntilChanged(e){let r=!1,i;return this.push(s=>{let n=s.payload;r&&(e?e(i,n):i===n)||(r=!0,i=n,s.isAvailable=!0)})}toJson(){return this.push(e=>{e.payload=JSON.stringify(e.payload),e.isAvailable=!0})}fromJson(){return this.push(e=>{e.payload=JSON.parse(e.payload),e.isAvailable=!0})}group(){return this}processChain(e){let r=this.chain,i=this.flow,s=r.length;for(let n=0;n<s;n++){if(i.isUnsubscribe=!1,i.isAvailable=!1,i.debounceMs=0,r[n](i),i.isUnsubscribe)return this.unsubscribe();if(i.debounceMs>0){i.debounceValue=i.payload,i.debounceIndex=n+1;let l=()=>{i.debounceTimer=0,i.payload=i.debounceValue,i.isBreak=!1;for(let a=i.debounceIndex;a<s;a++){if(i.isUnsubscribe=!1,i.isAvailable=!1,i.debounceMs=0,r[a](i),i.isUnsubscribe)return this.unsubscribe();if(i.debounceMs>0){i.debounceValue=i.payload,i.debounceIndex=a+1,clearTimeout(i.debounceTimer),i.debounceTimer=setTimeout(l,i.debounceMs);return}if(!i.isAvailable)return;if(i.isBreak)break}e&&e(i.payload)};clearTimeout(i.debounceTimer),i.debounceTimer=setTimeout(l,i.debounceMs);return}if(!i.isAvailable)return;if(i.isBreak)break}i.isAvailable=!0,e&&e(i.payload)}},f=class extends b{subscribe(e,r){return this.pipe.subscribe(e,r)}group(){return this.pipe}};var o=class extends h{observer;listener;errorHandler=(e,r)=>{console.log(`(Unit of SubscribeObject).send(${e}) ERROR:`,r)};_order=0;paused=!1;piped=!1;listeners;errorHandlers;constructor(e,r){super(),this.observer=e,this.piped=!!r}subscribe(e,r){return this.listener=v(e),r&&(this.errorHandler=r),this}add(e,r){if(this.listeners||(this.listeners=[],this.errorHandlers=[]),Array.isArray(e))for(let i=0;i<e.length;i++){this.listeners.push(e[i]);let s=r&&Array.isArray(r)?r[i]??this.errorHandler:r||this.errorHandler;this.errorHandlers.push(s)}else{this.listeners.push(e);let i=r&&!Array.isArray(r)?r:this.errorHandler;this.errorHandlers.push(i)}return this}unsubscribe(){this.observer&&(clearTimeout(this.flow.debounceTimer),this.observer.unSubscribe(this),this.observer=void 0,this.listener=void 0,this.chain.length=0)}send(e){let r=this.listener,i=this.listeners&&this.listeners.length>0;if(!r&&!i){this.unsubscribe();return}if(!(!this.observer||this.paused)){if(!this.piped){if(r)try{r(e)}catch(s){this.errorHandler(e,s)}return}try{if(this.flow.payload=e,this.flow.isBreak=!1,i){let s=this.listeners,n=this.errorHandlers;this.processChain(l=>{r&&r(l);for(let a=0;a<s.length;a++)try{s[a](l)}catch(O){n[a](l,O)}})}else this.processChain(r)}catch(s){this.errorHandler(e,s)}}}resume(){this.paused=!1}pause(){this.paused=!0}get order(){return this._order}set order(e){this._order=e}};var p=class{chain=[];flow={isBreak:!1,isAvailable:!1,payload:null};response={isOK:!1,payload:void 0};errHandler;get isEmpty(){return!this.chain.length}push(e){return this.chain.push(e),this}and(e){return this.push(r=>{e(r.payload)&&(r.isAvailable=!0)})}allOf(e){if(!Array.isArray(e))return this;for(let r=0;r<e.length;r++)this.and(e[r]);return this}choice(){return new T(this)}processChain(e){let r=this.chain,i=this.flow,s=this.response;s.isOK=!1,s.payload=void 0,i.payload=e,i.isBreak=!1;try{let n=r.length;for(let l=0;l<n;l++){if(i.isAvailable=!1,r[l](i),!i.isAvailable)return s;if(i.isBreak)break}}catch(n){return this.errHandler?this.errHandler(n,"Filter.processChain ERROR:"):console.log("Filter.processChain ERROR:",n),s}return s.isOK=!0,s.payload=i.payload,s}addErrorHandler(e){this.errHandler=e}},T=class extends b{};var c=class{subs=[];enabled=!0;killed=!1;process=!1;trash=[];filters=new p;_value;constructor(e){this._value=e}addFilter(e){return e&&this.filters.addErrorHandler(e),this.filters}disable(){this.enabled=!1}enable(){this.enabled=!0}get isEnable(){return this.enabled}next(e){if(this.killed||!this.enabled||!this.subs.length||!this.filters.isEmpty&&!this.filters.processChain(e).isOK)return;this.process=!0,this._value=e;let r=this.subs,i=r.length;for(let s=0;s<i;s++)r[s].send(e);if(this.process=!1,this.killed){this.clearDebounceTimers(),this._value=null,this.subs.length=0;return}this.trash.length&&this.clearTrash()}of(e){if(!this.killed&&this.enabled)for(let r=0;r<e.length;r++)this.next(e[r])}in(e){if(!this.killed&&this.enabled)for(let r in e)Object.hasOwn(e,r)&&this.next([r,e[r]])}clearTrash(){let e=this.trash.length;for(let r=0;r<e;r++)this.unSubscribe(this.trash[r]);this.trash.length=0}unSubscribe(e){if(!this.killed){if(this.process&&e){this.trash.push(e);return}this.subs&&u(this.subs,e)}}destroy(){this.killed||(this.killed=!0,this.process||(this.clearDebounceTimers(),this._value=null,this.subs.length=0))}unsubscribeAll(){if(!this.killed){if(this.process){this.clearDebounceTimers();let e=this.subs;for(let r=0;r<e.length;r++)this.trash.push(e[r]);return}this.clearDebounceTimers(),this.subs.length=0}}clearDebounceTimers(){let e=this.subs;for(let r=0;r<e.length;r++)clearTimeout(e[r].flow.debounceTimer)}getValue(){if(!this.killed)return this._value}size(){return this.killed?0:this.subs.length}subscribe(e,r){if(this.killed||!this.isListener(e))return;let i=new o(this,!1);return this.addObserver(i,e,r),i}addObserver(e,r,i){e.subscribe(r,i),this.subs.push(e)}isListener(e){return this.killed?!1:!!e}pipe(){if(this.killed)return;let e=new o(this,!0);return this.subs.push(e),e}get isDestroyed(){return this.killed}};var d=class extends o{constructor(e,r){super(e,r)}get order(){return this._order}set order(e){if(!this.observer||this.observer&&this.observer.isDestroyed){this._order=void 0;return}this._order=e,this.observer.sortByOrder()}subscribe(e,r){return super.subscribe(e,r),this}once(){return super.once()}take(e){return super.take(e)}skip(e){return super.skip(e)}scan(e,r){return super.scan(e,r)}};var y=class extends c{sortDirection=I;ascendingSort(){return this.sortDirection=I,this.sortByOrder()}descendingSort(){return this.sortDirection=k,this.sortByOrder()}sortByOrder(){return this.killed?!1:(this.subs.sort(this.sortDirection),!0)}subscribe(e,r){if(!this.isListener(e))return;let i=new d(this,!1);return this.addObserver(i,e,r),i}pipe(){if(this.killed)return;let e=new d(this,!0);return this.subs.push(e),e}unSubscribe(e){if(!this.killed){if(this.process&&e){this.trash.push(e);return}this.subs&&u(this.subs,e)}}};var m=class{arr=[];killed=!1;collect(...e){this.killed||this.arr.push(...e)}unsubscribe(e){this.killed||(e?.unsubscribe(),u(this.arr,e))}unsubscribeAll(){if(this.killed)return;let e=this.arr;for(let r=0;r<e.length;r++)e[r].unsubscribe();e.length=0}size(){return this.killed?0:this.arr.length}destroy(){this.unsubscribeAll(),this.arr.length=0,this.arr=0,this.killed=!0}get isDestroyed(){return this.killed}};export{m as Collector,c as Observable,y as OrderedObservable,u as deleteFromArray,C as quickDeleteFromArray};
|