@fluixi/reactive 1.0.0-alpha.82 → 1.0.0-alpha.84
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 +4 -0
- package/dist/cdn/reactive.cjs +2673 -1
- package/dist/cdn/reactive.global.js +2 -1
- package/dist/cdn/reactive.mjs +2657 -1
- package/dist/cdn/signal.cjs +299 -1
- package/dist/cdn/signal.d.ts +1 -1
- package/dist/cdn/signal.global.js +2 -1
- package/dist/cdn/signal.js +1 -1
- package/dist/cdn/signal.mjs +276 -1
- package/dist/index.cjs +2673 -1
- package/dist/index.mjs +2657 -1
- package/dist/lib/index.cjs +2674 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.mjs +2659 -1
- package/dist/lib/observable/index.cjs +386 -1
- package/dist/lib/observable/index.mjs +364 -1
- package/dist/lib/observable/observable.cjs +384 -1
- package/dist/lib/observable/observable.d.ts +0 -137
- package/dist/lib/observable/observable.d.ts.map +1 -1
- package/dist/lib/observable/observable.js +0 -71
- package/dist/lib/observable/observable.mjs +361 -1
- package/dist/lib/observable/subscription.cjs +180 -1
- package/dist/lib/observable/subscription.d.ts +0 -12
- package/dist/lib/observable/subscription.d.ts.map +1 -1
- package/dist/lib/observable/subscription.js +0 -12
- package/dist/lib/observable/subscription.mjs +157 -1
- package/dist/lib/observable/types.cjs +18 -1
- package/dist/lib/observable/types.d.ts.map +1 -1
- package/dist/lib/predicates.cjs +44 -1
- package/dist/lib/predicates.d.ts +2 -2
- package/dist/lib/predicates.js +2 -2
- package/dist/lib/predicates.mjs +23 -1
- package/dist/lib/signal/api.cjs +571 -1
- package/dist/lib/signal/api.d.ts +211 -1
- package/dist/lib/signal/api.d.ts.map +1 -1
- package/dist/lib/signal/api.js +207 -12
- package/dist/lib/signal/api.mjs +548 -1
- package/dist/lib/signal/cached-resource.cjs +672 -1
- package/dist/lib/signal/cached-resource.d.ts +28 -16
- package/dist/lib/signal/cached-resource.d.ts.map +1 -1
- package/dist/lib/signal/cached-resource.js +35 -29
- package/dist/lib/signal/cached-resource.mjs +650 -1
- package/dist/lib/signal/graph/children.cjs +325 -1
- package/dist/lib/signal/graph/children.js +1 -1
- package/dist/lib/signal/graph/children.mjs +302 -1
- package/dist/lib/signal/graph/compat.cjs +578 -1
- package/dist/lib/signal/graph/compat.d.ts +13 -13
- package/dist/lib/signal/graph/compat.d.ts.map +1 -1
- package/dist/lib/signal/graph/compat.js +51 -32
- package/dist/lib/signal/graph/compat.mjs +556 -1
- package/dist/lib/signal/graph/core.cjs +295 -1
- package/dist/lib/signal/graph/core.d.ts +28 -24
- package/dist/lib/signal/graph/core.d.ts.map +1 -1
- package/dist/lib/signal/graph/core.js +45 -31
- package/dist/lib/signal/graph/core.mjs +273 -1
- package/dist/lib/signal/graph/debounced.cjs +668 -1
- package/dist/lib/signal/graph/debounced.d.ts +5 -5
- package/dist/lib/signal/graph/debounced.d.ts.map +1 -1
- package/dist/lib/signal/graph/debounced.js +5 -5
- package/dist/lib/signal/graph/debounced.mjs +645 -1
- package/dist/lib/signal/graph/derived.cjs +496 -1
- package/dist/lib/signal/graph/derived.d.ts +1 -1
- package/dist/lib/signal/graph/derived.js +1 -1
- package/dist/lib/signal/graph/derived.mjs +473 -1
- package/dist/lib/signal/graph/detect.cjs +66 -1
- package/dist/lib/signal/graph/detect.mjs +45 -1
- package/dist/lib/signal/graph/error-boundary.cjs +301 -1
- package/dist/lib/signal/graph/error-boundary.js +3 -3
- package/dist/lib/signal/graph/error-boundary.mjs +278 -1
- package/dist/lib/signal/graph/index.cjs +305 -1
- package/dist/lib/signal/graph/index.d.ts +7 -6
- package/dist/lib/signal/graph/index.d.ts.map +1 -1
- package/dist/lib/signal/graph/index.js +7 -6
- package/dist/lib/signal/graph/index.mjs +283 -1
- package/dist/lib/signal/graph/observe.cjs +163 -0
- package/dist/lib/signal/graph/observe.d.ts +141 -0
- package/dist/lib/signal/graph/observe.d.ts.map +1 -0
- package/dist/lib/signal/graph/observe.js +149 -0
- package/dist/lib/signal/graph/observe.mjs +140 -0
- package/dist/lib/signal/graph/resource.cjs +620 -1
- package/dist/lib/signal/graph/resource.d.ts +1 -1
- package/dist/lib/signal/graph/resource.js +7 -8
- package/dist/lib/signal/graph/resource.mjs +597 -1
- package/dist/lib/signal/graph/runtime.cjs +501 -1
- package/dist/lib/signal/graph/runtime.d.ts +9 -9
- package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
- package/dist/lib/signal/graph/runtime.js +56 -37
- package/dist/lib/signal/graph/runtime.mjs +478 -1
- package/dist/lib/signal/graph/signal-next.cjs +1208 -1
- package/dist/lib/signal/graph/signal-next.d.ts +5 -5
- package/dist/lib/signal/graph/signal-next.d.ts.map +1 -1
- package/dist/lib/signal/graph/signal-next.js +14 -12
- package/dist/lib/signal/graph/signal-next.mjs +1186 -1
- package/dist/lib/signal/graph/ssr-hooks.cjs +60 -1
- package/dist/lib/signal/graph/ssr-hooks.d.ts +6 -7
- package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -1
- package/dist/lib/signal/graph/ssr-hooks.js +6 -7
- package/dist/lib/signal/graph/ssr-hooks.mjs +39 -1
- package/dist/lib/signal/graph/state.cjs +72 -1
- package/dist/lib/signal/graph/state.d.ts +43 -10
- package/dist/lib/signal/graph/state.d.ts.map +1 -1
- package/dist/lib/signal/graph/state.js +83 -21
- package/dist/lib/signal/graph/state.mjs +49 -1
- package/dist/lib/signal/graph/suspense.cjs +301 -1
- package/dist/lib/signal/graph/suspense.js +4 -4
- package/dist/lib/signal/graph/suspense.mjs +278 -1
- package/dist/lib/signal/index-legacy.cjs +2540 -1
- package/dist/lib/signal/index-legacy.d.ts +1 -1
- package/dist/lib/signal/index-legacy.js +1 -1
- package/dist/lib/signal/index-legacy.mjs +2518 -1
- package/dist/lib/signal/index.cjs +1275 -1
- package/dist/lib/signal/index.d.ts +5 -2
- package/dist/lib/signal/index.d.ts.map +1 -1
- package/dist/lib/signal/index.js +8 -3
- package/dist/lib/signal/index.mjs +1253 -1
- package/dist/lib/signal/list.cjs +549 -1
- package/dist/lib/signal/list.d.ts +5 -5
- package/dist/lib/signal/list.js +10 -10
- package/dist/lib/signal/list.mjs +526 -1
- package/dist/lib/signal/resource-api.cjs +626 -1
- package/dist/lib/signal/resource-api.d.ts +5 -5
- package/dist/lib/signal/resource-api.js +5 -5
- package/dist/lib/signal/resource-api.mjs +603 -1
- package/dist/lib/signal/signal.cjs +2023 -1
- package/dist/lib/signal/signal.d.ts +4 -4
- package/dist/lib/signal/signal.d.ts.map +1 -1
- package/dist/lib/signal/signal.js +22 -23
- package/dist/lib/signal/signal.mjs +2000 -1
- package/dist/lib/signal/types.cjs +38 -1
- package/dist/lib/signal/types.d.ts.map +1 -1
- package/dist/lib/signal/types.js +2 -2
- package/dist/lib/signal/types.mjs +17 -1
- package/dist/lib/signal/utilities.cjs +1012 -1
- package/dist/lib/signal/utilities.d.ts +0 -108
- package/dist/lib/signal/utilities.d.ts.map +1 -1
- package/dist/lib/signal/utilities.js +0 -158
- package/dist/lib/signal/utilities.mjs +990 -1
- package/dist/lib/store/api.cjs +612 -1
- package/dist/lib/store/api.d.ts +33 -0
- package/dist/lib/store/api.d.ts.map +1 -1
- package/dist/lib/store/api.js +41 -8
- package/dist/lib/store/api.mjs +596 -1
- package/dist/lib/store/index.cjs +691 -1
- package/dist/lib/store/index.js +1 -1
- package/dist/lib/store/index.mjs +676 -1
- package/dist/lib/store/setter.types.cjs +18 -1
- package/dist/lib/store/setter.types.d.ts +43 -3
- package/dist/lib/store/setter.types.d.ts.map +1 -1
- package/dist/lib/store/store.cjs +658 -1
- package/dist/lib/store/store.d.ts +72 -0
- package/dist/lib/store/store.d.ts.map +1 -1
- package/dist/lib/store/store.js +294 -11
- package/dist/lib/store/store.mjs +644 -1
- package/dist/lib/store/types.cjs +18 -1
- package/dist/lib/store/types.d.ts +1 -1
- package/dist/lib/store/types.d.ts.map +1 -1
- package/dist/lib/store/utils.cjs +43 -1
- package/dist/lib/store/utils.d.ts +1 -1
- package/dist/lib/store/utils.js +1 -1
- package/dist/lib/store/utils.mjs +22 -1
- package/dist/lib/subject.cjs +450 -1
- package/dist/lib/subject.js +3 -91
- package/dist/lib/subject.mjs +427 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/version.generated.cjs +27 -1
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +2 -2
- package/dist/version.generated.mjs +7 -1
- package/package.json +5 -4
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
// import { Subscription, toPromise } from "@fluixi/reactive";
|
|
2
|
-
// import { toPromise } from "./operators/index.js";
|
|
3
1
|
import { Subscription } from "./subscription.js";
|
|
4
2
|
/**
|
|
5
3
|
* A subscriber is both an Observer and a Subscription.
|
|
6
4
|
* This is the object that gets passed to the Observable's subscribe function.
|
|
7
5
|
*
|
|
8
|
-
* @template T - The type of values being observed
|
|
9
6
|
* @class Subscriber
|
|
10
7
|
* @extends {Subscription}
|
|
11
8
|
* @implements {Observer<T>}
|
|
@@ -15,11 +12,6 @@ export class Subscriber extends Subscription {
|
|
|
15
12
|
/** @private */ destination;
|
|
16
13
|
/**
|
|
17
14
|
* Creates a new Subscriber.
|
|
18
|
-
*
|
|
19
|
-
* @param {Partial<Observer<T>>|((value: T) => void)} [destinationOrNext] -
|
|
20
|
-
* Either an observer object or a next handler function
|
|
21
|
-
* @param {(error: any) => void} [error] - Error handler (if first param is next function)
|
|
22
|
-
* @param {() => void} [complete] - Complete handler (if first param is next function)
|
|
23
15
|
*/
|
|
24
16
|
constructor(destinationOrNext, error, complete) {
|
|
25
17
|
super();
|
|
@@ -42,9 +34,6 @@ export class Subscriber extends Subscription {
|
|
|
42
34
|
}
|
|
43
35
|
/**
|
|
44
36
|
* Sends the next value to the observer.
|
|
45
|
-
*
|
|
46
|
-
* @param {T} value - The value to send
|
|
47
|
-
* @returns {void}
|
|
48
37
|
*/
|
|
49
38
|
next(value) {
|
|
50
39
|
if (!this.isStopped && this.destination.next) {
|
|
@@ -58,9 +47,6 @@ export class Subscriber extends Subscription {
|
|
|
58
47
|
}
|
|
59
48
|
/**
|
|
60
49
|
* Sends an error notification to the observer.
|
|
61
|
-
*
|
|
62
|
-
* @param {any} err - The error to send
|
|
63
|
-
* @returns {void}
|
|
64
50
|
*/
|
|
65
51
|
error(err) {
|
|
66
52
|
if (!this.isStopped) {
|
|
@@ -82,8 +68,6 @@ export class Subscriber extends Subscription {
|
|
|
82
68
|
}
|
|
83
69
|
/**
|
|
84
70
|
* Sends a complete notification to the observer.
|
|
85
|
-
*
|
|
86
|
-
* @returns {void}
|
|
87
71
|
*/
|
|
88
72
|
complete() {
|
|
89
73
|
if (!this.isStopped) {
|
|
@@ -102,8 +86,6 @@ export class Subscriber extends Subscription {
|
|
|
102
86
|
}
|
|
103
87
|
/**
|
|
104
88
|
* Unsubscribes the subscriber.
|
|
105
|
-
*
|
|
106
|
-
* @returns {void}
|
|
107
89
|
*/
|
|
108
90
|
unsubscribe() {
|
|
109
91
|
if (this.closed) {
|
|
@@ -116,7 +98,6 @@ export class Subscriber extends Subscription {
|
|
|
116
98
|
/**
|
|
117
99
|
* SafeSubscriber adds extra safety checks to prevent reentrant calls.
|
|
118
100
|
*
|
|
119
|
-
* @template T - The type of values being observed
|
|
120
101
|
* @class SafeSubscriber
|
|
121
102
|
* @extends {Subscriber<T>}
|
|
122
103
|
*/
|
|
@@ -176,7 +157,6 @@ export function operate(destination) {
|
|
|
176
157
|
* A representation of any set of values over any amount of time.
|
|
177
158
|
* This is the most basic building block of RxJS.
|
|
178
159
|
*
|
|
179
|
-
* @template T - The type of values emitted by the Observable
|
|
180
160
|
* @class Observable
|
|
181
161
|
*
|
|
182
162
|
* @example
|
|
@@ -200,52 +180,6 @@ export function operate(destination) {
|
|
|
200
180
|
* // Later, unsubscribe
|
|
201
181
|
* subscription.unsubscribe();
|
|
202
182
|
*/
|
|
203
|
-
// export class Observable<T> extends Subscription {
|
|
204
|
-
// constructor(
|
|
205
|
-
// private _subscribeFn: (observer: Observer<T>) => void | (() => void) | Subscription
|
|
206
|
-
// ) {
|
|
207
|
-
// super()
|
|
208
|
-
// }
|
|
209
|
-
// subscribe(observer: Partial<Observer<T>> | ((v: T) => void)): Subscription {
|
|
210
|
-
// const finalObserver: Observer<T> =
|
|
211
|
-
// typeof observer === "function"
|
|
212
|
-
// ? { next: observer, error: () => {}, complete: () => {} }
|
|
213
|
-
// : {
|
|
214
|
-
// next: observer.next!,
|
|
215
|
-
// error: observer.error,
|
|
216
|
-
// complete: observer.complete
|
|
217
|
-
// } as Observer<T>;
|
|
218
|
-
// const subscription = new Subscription();
|
|
219
|
-
// const teardown = this._subscribeFn(finalObserver);
|
|
220
|
-
// if (typeof teardown === "function") {
|
|
221
|
-
// subscription.add(teardown);
|
|
222
|
-
// }
|
|
223
|
-
// return subscription;
|
|
224
|
-
// }
|
|
225
|
-
// /** Fully dynamic variadic pipe */
|
|
226
|
-
// pipe(): Observable<T>;
|
|
227
|
-
// pipe<A>(op1: OperatorFunction<T, A>): Observable<A>;
|
|
228
|
-
// pipe<A, B>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>): Observable<B>;
|
|
229
|
-
// pipe<A, B, C>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>): Observable<C>;
|
|
230
|
-
// pipe<A, B, C, D>(
|
|
231
|
-
// op1: OperatorFunction<T, A>,
|
|
232
|
-
// op2: OperatorFunction<A, B>,
|
|
233
|
-
// op3: OperatorFunction<B, C>,
|
|
234
|
-
// op4: OperatorFunction<C, D>
|
|
235
|
-
// ): Observable<D>;
|
|
236
|
-
// pipe<A, B, C, D, E>(
|
|
237
|
-
// op1: OperatorFunction<T, A>,
|
|
238
|
-
// op2: OperatorFunction<A, B>,
|
|
239
|
-
// op3: OperatorFunction<B, C>,
|
|
240
|
-
// op4: OperatorFunction<C, D>,
|
|
241
|
-
// op5: OperatorFunction<D, E>
|
|
242
|
-
// ): Observable<E>;
|
|
243
|
-
// // generic fallback for >5 operators (loses some inference but keeps runtime behavior)
|
|
244
|
-
// pipe(...ops: OperatorFunction<any, any>[]): Observable<any> {
|
|
245
|
-
// if (ops.length === 0) return this;
|
|
246
|
-
// return ops.reduce((prev, fn) => fn(prev), this as any);
|
|
247
|
-
// }
|
|
248
|
-
// }
|
|
249
183
|
export class Observable extends Subscription {
|
|
250
184
|
/**
|
|
251
185
|
* The function that is called when the Observable is subscribed to.
|
|
@@ -258,9 +192,6 @@ export class Observable extends Subscription {
|
|
|
258
192
|
_subscribe;
|
|
259
193
|
/**
|
|
260
194
|
* Creates a new Observable.
|
|
261
|
-
*
|
|
262
|
-
* @param {function(Subscriber<T>): (void | (() => void) | Subscription)} subscribe -
|
|
263
|
-
* The function that is called when the Observable is subscribed to
|
|
264
195
|
*/
|
|
265
196
|
constructor(subscribe) {
|
|
266
197
|
super();
|
|
@@ -313,8 +244,6 @@ export class Observable extends Subscription {
|
|
|
313
244
|
* The Promise resolves with the last emitted value when the Observable completes,
|
|
314
245
|
* or rejects if the Observable errors.
|
|
315
246
|
*
|
|
316
|
-
* @returns {Promise<T | undefined>} A Promise that resolves with the last value
|
|
317
|
-
*
|
|
318
247
|
* @example
|
|
319
248
|
* // Convert Observable to Promise
|
|
320
249
|
* const value = await of(1, 2, 3).toPromise();
|
|
@@ -1 +1,361 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/predicates.ts
|
|
2
|
+
function isFunction(value) {
|
|
3
|
+
return typeof value === "function" && !/^class\s/.test(Function.prototype.toString.call(value));
|
|
4
|
+
}
|
|
5
|
+
function isObject(value) {
|
|
6
|
+
if (value == null) return false;
|
|
7
|
+
if (Array.isArray(value)) return false;
|
|
8
|
+
if (typeof value === "function") return false;
|
|
9
|
+
if (value instanceof Date) return false;
|
|
10
|
+
if (value instanceof RegExp) return false;
|
|
11
|
+
if (value instanceof Map) return false;
|
|
12
|
+
if (value instanceof Set) return false;
|
|
13
|
+
if (value instanceof Error) return false;
|
|
14
|
+
return typeof value === "object";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// src/lib/observable/subscription.ts
|
|
18
|
+
var Subscription = class _Subscription {
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new Subscription.
|
|
21
|
+
*/
|
|
22
|
+
constructor(unsubscribe) {
|
|
23
|
+
/** @private */
|
|
24
|
+
this._closed = false;
|
|
25
|
+
/** @private */
|
|
26
|
+
this._parentOrParents = null;
|
|
27
|
+
/** @private */
|
|
28
|
+
this._subscriptions = null;
|
|
29
|
+
if (unsubscribe) {
|
|
30
|
+
this._subscriptions = [unsubscribe];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Whether the subscription is closed.
|
|
35
|
+
*/
|
|
36
|
+
get closed() {
|
|
37
|
+
return this._closed;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Disposes the resources held by the subscription.
|
|
41
|
+
* May be called multiple times (idempotent).
|
|
42
|
+
*/
|
|
43
|
+
unsubscribe() {
|
|
44
|
+
if (this._closed) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
this._closed = true;
|
|
48
|
+
const { _parentOrParents, _subscriptions } = this;
|
|
49
|
+
if (_parentOrParents instanceof _Subscription) {
|
|
50
|
+
_parentOrParents.remove(this);
|
|
51
|
+
} else if (_parentOrParents !== null) {
|
|
52
|
+
for (const parent of _parentOrParents) {
|
|
53
|
+
parent.remove(this);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (_subscriptions) {
|
|
57
|
+
for (const sub of _subscriptions) {
|
|
58
|
+
if (isFunction(sub) && !(sub instanceof _Subscription)) {
|
|
59
|
+
try {
|
|
60
|
+
sub();
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error("Error in unsubscribe function:", error);
|
|
63
|
+
}
|
|
64
|
+
} else if (isObject(sub) && typeof sub.unsubscribe === "function") {
|
|
65
|
+
try {
|
|
66
|
+
sub.unsubscribe();
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error("Error unsubscribing child:", error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
this._subscriptions = null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Adds a child subscription or cleanup function to this subscription.
|
|
77
|
+
* When this subscription is unsubscribed, all added subscriptions/functions will be unsubscribed/called.
|
|
78
|
+
*
|
|
79
|
+
* @throws {TypeError} If the argument is not a subscription-like object or function
|
|
80
|
+
*/
|
|
81
|
+
add(subscription) {
|
|
82
|
+
if (!subscription || subscription === this) {
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
if (subscription.closed) {
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
let { _closed, _subscriptions } = this;
|
|
89
|
+
if (_closed) {
|
|
90
|
+
if (isFunction(subscription)) {
|
|
91
|
+
try {
|
|
92
|
+
subscription();
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error("Error in unsubscribe function:", error);
|
|
95
|
+
}
|
|
96
|
+
} else if (subscription.unsubscribe) {
|
|
97
|
+
try {
|
|
98
|
+
subscription.unsubscribe();
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error("Error unsubscribing:", error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
if (!_subscriptions) {
|
|
106
|
+
this._subscriptions = [];
|
|
107
|
+
}
|
|
108
|
+
this._subscriptions.push(subscription);
|
|
109
|
+
if (subscription instanceof _Subscription) {
|
|
110
|
+
subscription._addParent(this);
|
|
111
|
+
}
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Removes a child subscription from this subscription.
|
|
116
|
+
*/
|
|
117
|
+
remove(subscription) {
|
|
118
|
+
const { _subscriptions } = this;
|
|
119
|
+
if (!_subscriptions) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const index = _subscriptions.indexOf(subscription);
|
|
123
|
+
if (index !== -1) {
|
|
124
|
+
_subscriptions.splice(index, 1);
|
|
125
|
+
subscription._removeParent(this);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** @private */
|
|
129
|
+
_addParent(parent) {
|
|
130
|
+
const { _parentOrParents } = this;
|
|
131
|
+
if (!_parentOrParents) {
|
|
132
|
+
this._parentOrParents = parent;
|
|
133
|
+
} else if (Array.isArray(_parentOrParents)) {
|
|
134
|
+
_parentOrParents.push(parent);
|
|
135
|
+
} else {
|
|
136
|
+
this._parentOrParents = [_parentOrParents, parent];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** @private */
|
|
140
|
+
_removeParent(parent) {
|
|
141
|
+
const { _parentOrParents } = this;
|
|
142
|
+
if (_parentOrParents === parent) {
|
|
143
|
+
this._parentOrParents = null;
|
|
144
|
+
} else if (Array.isArray(_parentOrParents)) {
|
|
145
|
+
const index = _parentOrParents.indexOf(parent);
|
|
146
|
+
if (index !== -1) {
|
|
147
|
+
_parentOrParents.splice(index, 1);
|
|
148
|
+
if (_parentOrParents.length === 1) {
|
|
149
|
+
this._parentOrParents = _parentOrParents[0];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// src/lib/observable/observable.ts
|
|
157
|
+
var Subscriber = class extends Subscription {
|
|
158
|
+
/**
|
|
159
|
+
* Creates a new Subscriber.
|
|
160
|
+
*/
|
|
161
|
+
constructor(destinationOrNext, error, complete) {
|
|
162
|
+
super();
|
|
163
|
+
/** @private */
|
|
164
|
+
this.isStopped = false;
|
|
165
|
+
let observer;
|
|
166
|
+
if (!destinationOrNext) {
|
|
167
|
+
observer = {};
|
|
168
|
+
} else if (typeof destinationOrNext === "object") {
|
|
169
|
+
observer = destinationOrNext;
|
|
170
|
+
} else {
|
|
171
|
+
observer = {
|
|
172
|
+
next: destinationOrNext,
|
|
173
|
+
error,
|
|
174
|
+
complete
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
this.destination = observer;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Sends the next value to the observer.
|
|
181
|
+
*/
|
|
182
|
+
next(value) {
|
|
183
|
+
if (!this.isStopped && this.destination.next) {
|
|
184
|
+
try {
|
|
185
|
+
this.destination.next(value);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
this.error(error);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Sends an error notification to the observer.
|
|
193
|
+
*/
|
|
194
|
+
error(err) {
|
|
195
|
+
if (!this.isStopped) {
|
|
196
|
+
this.isStopped = true;
|
|
197
|
+
if (this.destination.error) {
|
|
198
|
+
try {
|
|
199
|
+
this.destination.error(err);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
throw err;
|
|
205
|
+
}
|
|
206
|
+
this.unsubscribe();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Sends a complete notification to the observer.
|
|
211
|
+
*/
|
|
212
|
+
complete() {
|
|
213
|
+
if (!this.isStopped) {
|
|
214
|
+
this.isStopped = true;
|
|
215
|
+
if (this.destination.complete) {
|
|
216
|
+
try {
|
|
217
|
+
this.destination.complete();
|
|
218
|
+
} catch (error) {
|
|
219
|
+
this.error(error);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
this.unsubscribe();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Unsubscribes the subscriber.
|
|
228
|
+
*/
|
|
229
|
+
unsubscribe() {
|
|
230
|
+
if (this.closed) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
this.isStopped = true;
|
|
234
|
+
super.unsubscribe();
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var SafeSubscriber = class extends Subscriber {
|
|
238
|
+
constructor(observerOrNext, error, complete, parentSubscriber) {
|
|
239
|
+
super(observerOrNext, error, complete);
|
|
240
|
+
/** @private */
|
|
241
|
+
this._isUnsubscribing = false;
|
|
242
|
+
/** @private */
|
|
243
|
+
this._parentSubscriber = null;
|
|
244
|
+
this._parentSubscriber = parentSubscriber || null;
|
|
245
|
+
}
|
|
246
|
+
next(value) {
|
|
247
|
+
if (!this.isStopped && !this._isUnsubscribing) {
|
|
248
|
+
try {
|
|
249
|
+
super.next(value);
|
|
250
|
+
} catch (error) {
|
|
251
|
+
this.error(error);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
error(err) {
|
|
256
|
+
if (!this.isStopped && !this._isUnsubscribing) {
|
|
257
|
+
this._isUnsubscribing = true;
|
|
258
|
+
try {
|
|
259
|
+
super.error(err);
|
|
260
|
+
} finally {
|
|
261
|
+
this._isUnsubscribing = false;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
complete() {
|
|
266
|
+
if (!this.isStopped && !this._isUnsubscribing) {
|
|
267
|
+
this._isUnsubscribing = true;
|
|
268
|
+
try {
|
|
269
|
+
super.complete();
|
|
270
|
+
} finally {
|
|
271
|
+
this._isUnsubscribing = false;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
unsubscribe() {
|
|
276
|
+
if (this.closed) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
this._isUnsubscribing = true;
|
|
280
|
+
super.unsubscribe();
|
|
281
|
+
this._isUnsubscribing = false;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
function operate(destination) {
|
|
285
|
+
return new Subscriber(destination.next, destination.error, destination.complete);
|
|
286
|
+
}
|
|
287
|
+
var Observable = class extends Subscription {
|
|
288
|
+
/**
|
|
289
|
+
* Creates a new Observable.
|
|
290
|
+
*/
|
|
291
|
+
constructor(subscribe) {
|
|
292
|
+
super();
|
|
293
|
+
if (subscribe) {
|
|
294
|
+
this._subscribe = subscribe;
|
|
295
|
+
} else {
|
|
296
|
+
throw new TypeError("Observable constructor requires a subscribe function");
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
subscribe(observerOrNext, error, complete) {
|
|
300
|
+
let subscriber;
|
|
301
|
+
if (observerOrNext instanceof Subscriber) {
|
|
302
|
+
subscriber = observerOrNext;
|
|
303
|
+
} else {
|
|
304
|
+
subscriber = new SafeSubscriber(observerOrNext, error, complete);
|
|
305
|
+
}
|
|
306
|
+
const { _subscribe } = this;
|
|
307
|
+
try {
|
|
308
|
+
const result = _subscribe.call(this, subscriber);
|
|
309
|
+
if (result) {
|
|
310
|
+
if (typeof result === "function") {
|
|
311
|
+
subscriber.add(result);
|
|
312
|
+
} else if (typeof result.unsubscribe === "function") {
|
|
313
|
+
subscriber.add(result);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
} catch (err) {
|
|
317
|
+
subscriber.error(err);
|
|
318
|
+
}
|
|
319
|
+
return subscriber;
|
|
320
|
+
}
|
|
321
|
+
pipe(...operations) {
|
|
322
|
+
if (operations.length === 0) {
|
|
323
|
+
return this;
|
|
324
|
+
}
|
|
325
|
+
return operations.reduce(
|
|
326
|
+
(prev, fn) => fn(prev),
|
|
327
|
+
this
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Converts the Observable to a Promise.
|
|
332
|
+
* The Promise resolves with the last emitted value when the Observable completes,
|
|
333
|
+
* or rejects if the Observable errors.
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* // Convert Observable to Promise
|
|
337
|
+
* const value = await of(1, 2, 3).toPromise();
|
|
338
|
+
* console.log(value); // 3
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* // Handle empty Observable
|
|
342
|
+
* const value = await EMPTY.toPromise();
|
|
343
|
+
* console.log(value); // undefined
|
|
344
|
+
*/
|
|
345
|
+
toPromise() {
|
|
346
|
+
return new Promise((resolve, reject) => {
|
|
347
|
+
let lastValue;
|
|
348
|
+
this.subscribe({
|
|
349
|
+
next: (value) => lastValue = value,
|
|
350
|
+
error: reject,
|
|
351
|
+
complete: () => resolve(lastValue)
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
export {
|
|
357
|
+
Observable,
|
|
358
|
+
SafeSubscriber,
|
|
359
|
+
Subscriber,
|
|
360
|
+
operate
|
|
361
|
+
};
|
|
@@ -1 +1,180 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/observable/subscription.ts
|
|
21
|
+
var subscription_exports = {};
|
|
22
|
+
__export(subscription_exports, {
|
|
23
|
+
Subscription: () => Subscription
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(subscription_exports);
|
|
26
|
+
|
|
27
|
+
// src/lib/predicates.ts
|
|
28
|
+
function isFunction(value) {
|
|
29
|
+
return typeof value === "function" && !/^class\s/.test(Function.prototype.toString.call(value));
|
|
30
|
+
}
|
|
31
|
+
function isObject(value) {
|
|
32
|
+
if (value == null) return false;
|
|
33
|
+
if (Array.isArray(value)) return false;
|
|
34
|
+
if (typeof value === "function") return false;
|
|
35
|
+
if (value instanceof Date) return false;
|
|
36
|
+
if (value instanceof RegExp) return false;
|
|
37
|
+
if (value instanceof Map) return false;
|
|
38
|
+
if (value instanceof Set) return false;
|
|
39
|
+
if (value instanceof Error) return false;
|
|
40
|
+
return typeof value === "object";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/lib/observable/subscription.ts
|
|
44
|
+
var Subscription = class _Subscription {
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new Subscription.
|
|
47
|
+
*/
|
|
48
|
+
constructor(unsubscribe) {
|
|
49
|
+
/** @private */
|
|
50
|
+
this._closed = false;
|
|
51
|
+
/** @private */
|
|
52
|
+
this._parentOrParents = null;
|
|
53
|
+
/** @private */
|
|
54
|
+
this._subscriptions = null;
|
|
55
|
+
if (unsubscribe) {
|
|
56
|
+
this._subscriptions = [unsubscribe];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether the subscription is closed.
|
|
61
|
+
*/
|
|
62
|
+
get closed() {
|
|
63
|
+
return this._closed;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Disposes the resources held by the subscription.
|
|
67
|
+
* May be called multiple times (idempotent).
|
|
68
|
+
*/
|
|
69
|
+
unsubscribe() {
|
|
70
|
+
if (this._closed) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this._closed = true;
|
|
74
|
+
const { _parentOrParents, _subscriptions } = this;
|
|
75
|
+
if (_parentOrParents instanceof _Subscription) {
|
|
76
|
+
_parentOrParents.remove(this);
|
|
77
|
+
} else if (_parentOrParents !== null) {
|
|
78
|
+
for (const parent of _parentOrParents) {
|
|
79
|
+
parent.remove(this);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (_subscriptions) {
|
|
83
|
+
for (const sub of _subscriptions) {
|
|
84
|
+
if (isFunction(sub) && !(sub instanceof _Subscription)) {
|
|
85
|
+
try {
|
|
86
|
+
sub();
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error("Error in unsubscribe function:", error);
|
|
89
|
+
}
|
|
90
|
+
} else if (isObject(sub) && typeof sub.unsubscribe === "function") {
|
|
91
|
+
try {
|
|
92
|
+
sub.unsubscribe();
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error("Error unsubscribing child:", error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
this._subscriptions = null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Adds a child subscription or cleanup function to this subscription.
|
|
103
|
+
* When this subscription is unsubscribed, all added subscriptions/functions will be unsubscribed/called.
|
|
104
|
+
*
|
|
105
|
+
* @throws {TypeError} If the argument is not a subscription-like object or function
|
|
106
|
+
*/
|
|
107
|
+
add(subscription) {
|
|
108
|
+
if (!subscription || subscription === this) {
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
if (subscription.closed) {
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
let { _closed, _subscriptions } = this;
|
|
115
|
+
if (_closed) {
|
|
116
|
+
if (isFunction(subscription)) {
|
|
117
|
+
try {
|
|
118
|
+
subscription();
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error("Error in unsubscribe function:", error);
|
|
121
|
+
}
|
|
122
|
+
} else if (subscription.unsubscribe) {
|
|
123
|
+
try {
|
|
124
|
+
subscription.unsubscribe();
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error("Error unsubscribing:", error);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
if (!_subscriptions) {
|
|
132
|
+
this._subscriptions = [];
|
|
133
|
+
}
|
|
134
|
+
this._subscriptions.push(subscription);
|
|
135
|
+
if (subscription instanceof _Subscription) {
|
|
136
|
+
subscription._addParent(this);
|
|
137
|
+
}
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Removes a child subscription from this subscription.
|
|
142
|
+
*/
|
|
143
|
+
remove(subscription) {
|
|
144
|
+
const { _subscriptions } = this;
|
|
145
|
+
if (!_subscriptions) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const index = _subscriptions.indexOf(subscription);
|
|
149
|
+
if (index !== -1) {
|
|
150
|
+
_subscriptions.splice(index, 1);
|
|
151
|
+
subscription._removeParent(this);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** @private */
|
|
155
|
+
_addParent(parent) {
|
|
156
|
+
const { _parentOrParents } = this;
|
|
157
|
+
if (!_parentOrParents) {
|
|
158
|
+
this._parentOrParents = parent;
|
|
159
|
+
} else if (Array.isArray(_parentOrParents)) {
|
|
160
|
+
_parentOrParents.push(parent);
|
|
161
|
+
} else {
|
|
162
|
+
this._parentOrParents = [_parentOrParents, parent];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/** @private */
|
|
166
|
+
_removeParent(parent) {
|
|
167
|
+
const { _parentOrParents } = this;
|
|
168
|
+
if (_parentOrParents === parent) {
|
|
169
|
+
this._parentOrParents = null;
|
|
170
|
+
} else if (Array.isArray(_parentOrParents)) {
|
|
171
|
+
const index = _parentOrParents.indexOf(parent);
|
|
172
|
+
if (index !== -1) {
|
|
173
|
+
_parentOrParents.splice(index, 1);
|
|
174
|
+
if (_parentOrParents.length === 1) {
|
|
175
|
+
this._parentOrParents = _parentOrParents[0];
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|