@fluixi/reactive 1.0.0-alpha.83 → 1.0.0-alpha.85

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.
Files changed (167) hide show
  1. package/dist/cdn/reactive.cjs +2722 -1
  2. package/dist/cdn/reactive.global.js +2 -1
  3. package/dist/cdn/reactive.mjs +2706 -1
  4. package/dist/cdn/signal.cjs +299 -1
  5. package/dist/cdn/signal.d.ts +1 -1
  6. package/dist/cdn/signal.global.js +2 -1
  7. package/dist/cdn/signal.js +1 -1
  8. package/dist/cdn/signal.mjs +276 -1
  9. package/dist/index.cjs +2722 -1
  10. package/dist/index.mjs +2706 -1
  11. package/dist/lib/index.cjs +2723 -1
  12. package/dist/lib/index.js +1 -1
  13. package/dist/lib/index.mjs +2708 -1
  14. package/dist/lib/observable/index.cjs +386 -1
  15. package/dist/lib/observable/index.mjs +364 -1
  16. package/dist/lib/observable/observable.cjs +384 -1
  17. package/dist/lib/observable/observable.d.ts +0 -137
  18. package/dist/lib/observable/observable.d.ts.map +1 -1
  19. package/dist/lib/observable/observable.js +0 -71
  20. package/dist/lib/observable/observable.mjs +361 -1
  21. package/dist/lib/observable/subscription.cjs +180 -1
  22. package/dist/lib/observable/subscription.d.ts +0 -12
  23. package/dist/lib/observable/subscription.d.ts.map +1 -1
  24. package/dist/lib/observable/subscription.js +0 -12
  25. package/dist/lib/observable/subscription.mjs +157 -1
  26. package/dist/lib/observable/types.cjs +18 -1
  27. package/dist/lib/observable/types.d.ts.map +1 -1
  28. package/dist/lib/predicates.cjs +44 -1
  29. package/dist/lib/predicates.d.ts +2 -2
  30. package/dist/lib/predicates.js +2 -2
  31. package/dist/lib/predicates.mjs +23 -1
  32. package/dist/lib/signal/api.cjs +571 -1
  33. package/dist/lib/signal/api.d.ts +211 -1
  34. package/dist/lib/signal/api.d.ts.map +1 -1
  35. package/dist/lib/signal/api.js +207 -12
  36. package/dist/lib/signal/api.mjs +548 -1
  37. package/dist/lib/signal/cached-resource.cjs +672 -1
  38. package/dist/lib/signal/cached-resource.d.ts +28 -16
  39. package/dist/lib/signal/cached-resource.d.ts.map +1 -1
  40. package/dist/lib/signal/cached-resource.js +35 -29
  41. package/dist/lib/signal/cached-resource.mjs +650 -1
  42. package/dist/lib/signal/graph/children.cjs +325 -1
  43. package/dist/lib/signal/graph/children.js +1 -1
  44. package/dist/lib/signal/graph/children.mjs +302 -1
  45. package/dist/lib/signal/graph/compat.cjs +578 -1
  46. package/dist/lib/signal/graph/compat.d.ts +13 -13
  47. package/dist/lib/signal/graph/compat.d.ts.map +1 -1
  48. package/dist/lib/signal/graph/compat.js +33 -31
  49. package/dist/lib/signal/graph/compat.mjs +556 -1
  50. package/dist/lib/signal/graph/core.cjs +295 -1
  51. package/dist/lib/signal/graph/core.d.ts +28 -24
  52. package/dist/lib/signal/graph/core.d.ts.map +1 -1
  53. package/dist/lib/signal/graph/core.js +38 -31
  54. package/dist/lib/signal/graph/core.mjs +273 -1
  55. package/dist/lib/signal/graph/debounced.cjs +668 -1
  56. package/dist/lib/signal/graph/debounced.d.ts +5 -5
  57. package/dist/lib/signal/graph/debounced.d.ts.map +1 -1
  58. package/dist/lib/signal/graph/debounced.js +5 -5
  59. package/dist/lib/signal/graph/debounced.mjs +645 -1
  60. package/dist/lib/signal/graph/derived.cjs +496 -1
  61. package/dist/lib/signal/graph/derived.d.ts +1 -1
  62. package/dist/lib/signal/graph/derived.js +1 -1
  63. package/dist/lib/signal/graph/derived.mjs +473 -1
  64. package/dist/lib/signal/graph/detect.cjs +66 -1
  65. package/dist/lib/signal/graph/detect.mjs +45 -1
  66. package/dist/lib/signal/graph/error-boundary.cjs +301 -1
  67. package/dist/lib/signal/graph/error-boundary.js +3 -3
  68. package/dist/lib/signal/graph/error-boundary.mjs +278 -1
  69. package/dist/lib/signal/graph/index.cjs +305 -1
  70. package/dist/lib/signal/graph/index.d.ts +7 -6
  71. package/dist/lib/signal/graph/index.d.ts.map +1 -1
  72. package/dist/lib/signal/graph/index.js +7 -6
  73. package/dist/lib/signal/graph/index.mjs +283 -1
  74. package/dist/lib/signal/graph/observe.cjs +163 -1
  75. package/dist/lib/signal/graph/observe.d.ts +8 -8
  76. package/dist/lib/signal/graph/observe.js +5 -5
  77. package/dist/lib/signal/graph/observe.mjs +140 -1
  78. package/dist/lib/signal/graph/resource.cjs +620 -1
  79. package/dist/lib/signal/graph/resource.d.ts +1 -1
  80. package/dist/lib/signal/graph/resource.js +7 -8
  81. package/dist/lib/signal/graph/resource.mjs +597 -1
  82. package/dist/lib/signal/graph/runtime.cjs +501 -1
  83. package/dist/lib/signal/graph/runtime.d.ts +7 -7
  84. package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
  85. package/dist/lib/signal/graph/runtime.js +34 -30
  86. package/dist/lib/signal/graph/runtime.mjs +478 -1
  87. package/dist/lib/signal/graph/signal-next.cjs +1208 -1
  88. package/dist/lib/signal/graph/signal-next.d.ts +5 -5
  89. package/dist/lib/signal/graph/signal-next.d.ts.map +1 -1
  90. package/dist/lib/signal/graph/signal-next.js +14 -12
  91. package/dist/lib/signal/graph/signal-next.mjs +1186 -1
  92. package/dist/lib/signal/graph/ssr-hooks.cjs +60 -1
  93. package/dist/lib/signal/graph/ssr-hooks.d.ts +6 -7
  94. package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -1
  95. package/dist/lib/signal/graph/ssr-hooks.js +6 -7
  96. package/dist/lib/signal/graph/ssr-hooks.mjs +39 -1
  97. package/dist/lib/signal/graph/state.cjs +72 -1
  98. package/dist/lib/signal/graph/state.d.ts +41 -10
  99. package/dist/lib/signal/graph/state.d.ts.map +1 -1
  100. package/dist/lib/signal/graph/state.js +83 -22
  101. package/dist/lib/signal/graph/state.mjs +49 -1
  102. package/dist/lib/signal/graph/suspense.cjs +301 -1
  103. package/dist/lib/signal/graph/suspense.js +4 -4
  104. package/dist/lib/signal/graph/suspense.mjs +278 -1
  105. package/dist/lib/signal/index-legacy.cjs +2540 -1
  106. package/dist/lib/signal/index-legacy.d.ts +1 -1
  107. package/dist/lib/signal/index-legacy.js +1 -1
  108. package/dist/lib/signal/index-legacy.mjs +2518 -1
  109. package/dist/lib/signal/index.cjs +1275 -1
  110. package/dist/lib/signal/index.d.ts +3 -2
  111. package/dist/lib/signal/index.d.ts.map +1 -1
  112. package/dist/lib/signal/index.js +7 -4
  113. package/dist/lib/signal/index.mjs +1253 -1
  114. package/dist/lib/signal/list.cjs +549 -1
  115. package/dist/lib/signal/list.d.ts +5 -5
  116. package/dist/lib/signal/list.js +5 -5
  117. package/dist/lib/signal/list.mjs +526 -1
  118. package/dist/lib/signal/resource-api.cjs +626 -1
  119. package/dist/lib/signal/resource-api.d.ts +5 -5
  120. package/dist/lib/signal/resource-api.js +5 -5
  121. package/dist/lib/signal/resource-api.mjs +603 -1
  122. package/dist/lib/signal/signal.cjs +2023 -1
  123. package/dist/lib/signal/signal.d.ts +4 -4
  124. package/dist/lib/signal/signal.d.ts.map +1 -1
  125. package/dist/lib/signal/signal.js +22 -23
  126. package/dist/lib/signal/signal.mjs +2000 -1
  127. package/dist/lib/signal/types.cjs +38 -1
  128. package/dist/lib/signal/types.d.ts.map +1 -1
  129. package/dist/lib/signal/types.js +2 -2
  130. package/dist/lib/signal/types.mjs +17 -1
  131. package/dist/lib/signal/utilities.cjs +1012 -1
  132. package/dist/lib/signal/utilities.d.ts +0 -108
  133. package/dist/lib/signal/utilities.d.ts.map +1 -1
  134. package/dist/lib/signal/utilities.js +0 -158
  135. package/dist/lib/signal/utilities.mjs +990 -1
  136. package/dist/lib/store/api.cjs +661 -1
  137. package/dist/lib/store/api.d.ts +33 -0
  138. package/dist/lib/store/api.d.ts.map +1 -1
  139. package/dist/lib/store/api.js +41 -8
  140. package/dist/lib/store/api.mjs +645 -1
  141. package/dist/lib/store/index.cjs +740 -1
  142. package/dist/lib/store/index.js +1 -1
  143. package/dist/lib/store/index.mjs +725 -1
  144. package/dist/lib/store/setter.types.cjs +18 -1
  145. package/dist/lib/store/setter.types.d.ts +43 -3
  146. package/dist/lib/store/setter.types.d.ts.map +1 -1
  147. package/dist/lib/store/store.cjs +707 -1
  148. package/dist/lib/store/store.d.ts +72 -0
  149. package/dist/lib/store/store.d.ts.map +1 -1
  150. package/dist/lib/store/store.js +238 -8
  151. package/dist/lib/store/store.mjs +693 -1
  152. package/dist/lib/store/types.cjs +18 -1
  153. package/dist/lib/store/types.d.ts +1 -1
  154. package/dist/lib/store/types.d.ts.map +1 -1
  155. package/dist/lib/store/utils.cjs +43 -1
  156. package/dist/lib/store/utils.d.ts +1 -1
  157. package/dist/lib/store/utils.js +1 -1
  158. package/dist/lib/store/utils.mjs +22 -1
  159. package/dist/lib/subject.cjs +450 -1
  160. package/dist/lib/subject.js +3 -91
  161. package/dist/lib/subject.mjs +427 -1
  162. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  163. package/dist/version.generated.cjs +27 -1
  164. package/dist/version.generated.d.ts +1 -1
  165. package/dist/version.generated.js +2 -2
  166. package/dist/version.generated.mjs +7 -1
  167. 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
- function c(i){return typeof i=="function"&&!/^class\s/.test(Function.prototype.toString.call(i))}function b(i){return i==null||Array.isArray(i)||typeof i=="function"||i instanceof Date||i instanceof RegExp||i instanceof Map||i instanceof Set||i instanceof Error?!1:typeof i=="object"}var p=class i{constructor(e){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;e&&(this._subscriptions=[e])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:e,_subscriptions:r}=this;if(e instanceof i)e.remove(this);else if(e!==null)for(let t of e)t.remove(this);if(r){for(let t of r)if(c(t)&&!(t instanceof i))try{t()}catch(o){console.error("Error in unsubscribe function:",o)}else if(b(t)&&typeof t.unsubscribe=="function")try{t.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(e){if(!e||e===this)return this;if(e.closed)return this;let{_closed:r,_subscriptions:t}=this;if(r){if(c(e))try{e()}catch(o){console.error("Error in unsubscribe function:",o)}else if(e.unsubscribe)try{e.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return t||(this._subscriptions=[]),this._subscriptions.push(e),e instanceof i&&e._addParent(this),this}remove(e){let{_subscriptions:r}=this;if(!r)return;let t=r.indexOf(e);t!==-1&&(r.splice(t,1),e._removeParent(this))}_addParent(e){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(e):this._parentOrParents=[r,e]:this._parentOrParents=e}_removeParent(e){let{_parentOrParents:r}=this;if(r===e)this._parentOrParents=null;else if(Array.isArray(r)){let t=r.indexOf(e);t!==-1&&(r.splice(t,1),r.length===1&&(this._parentOrParents=r[0]))}}};var u=class extends p{constructor(r,t,o){super();this.isStopped=!1;let n;r?typeof r=="object"?n=r:n={next:r,error:t,complete:o}:n={},this.destination=n}next(r){if(!this.isStopped&&this.destination.next)try{this.destination.next(r)}catch(t){this.error(t)}}error(r){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(r)}catch(t){throw t}else throw r;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(r){this.error(r);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},a=class extends u{constructor(r,t,o,n){super(r,t,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=n||null}next(r){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(r)}catch(t){this.error(t)}}error(r){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(r)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};function v(i){return new u(i.next,i.error,i.complete)}var l=class extends p{constructor(e){if(super(),e)this._subscribe=e;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(e,r,t){let o;e instanceof u?o=e:o=new a(e,r,t);let{_subscribe:n}=this;try{let s=n.call(this,o);s&&(typeof s=="function"||typeof s.unsubscribe=="function")&&o.add(s)}catch(s){o.error(s)}return o}pipe(...e){return e.length===0?this:e.reduce((r,t)=>t(r),this)}toPromise(){return new Promise((e,r)=>{let t;this.subscribe({next:o=>t=o,error:r,complete:()=>e(t)})})}};export{l as Observable,a as SafeSubscriber,u as Subscriber,v as operate};
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";var e=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var b=(i,r)=>{for(var n in r)e(i,n,{get:r[n],enumerable:!0})},p=(i,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of a(r))!l.call(i,t)&&t!==n&&e(i,t,{get:()=>r[t],enumerable:!(s=u(r,t))||s.enumerable});return i};var h=i=>p(e({},"__esModule",{value:!0}),i);var d={};b(d,{Subscription:()=>c});module.exports=h(d);function o(i){return typeof i=="function"&&!/^class\s/.test(Function.prototype.toString.call(i))}function f(i){return i==null||Array.isArray(i)||typeof i=="function"||i instanceof Date||i instanceof RegExp||i instanceof Map||i instanceof Set||i instanceof Error?!1:typeof i=="object"}var c=class i{constructor(r){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;r&&(this._subscriptions=[r])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:r,_subscriptions:n}=this;if(r instanceof i)r.remove(this);else if(r!==null)for(let s of r)s.remove(this);if(n){for(let s of n)if(o(s)&&!(s instanceof i))try{s()}catch(t){console.error("Error in unsubscribe function:",t)}else if(f(s)&&typeof s.unsubscribe=="function")try{s.unsubscribe()}catch(t){console.error("Error unsubscribing child:",t)}this._subscriptions=null}}add(r){if(!r||r===this)return this;if(r.closed)return this;let{_closed:n,_subscriptions:s}=this;if(n){if(o(r))try{r()}catch(t){console.error("Error in unsubscribe function:",t)}else if(r.unsubscribe)try{r.unsubscribe()}catch(t){console.error("Error unsubscribing:",t)}return this}return s||(this._subscriptions=[]),this._subscriptions.push(r),r instanceof i&&r._addParent(this),this}remove(r){let{_subscriptions:n}=this;if(!n)return;let s=n.indexOf(r);s!==-1&&(n.splice(s,1),r._removeParent(this))}_addParent(r){let{_parentOrParents:n}=this;n?Array.isArray(n)?n.push(r):this._parentOrParents=[n,r]:this._parentOrParents=r}_removeParent(r){let{_parentOrParents:n}=this;if(n===r)this._parentOrParents=null;else if(Array.isArray(n)){let s=n.indexOf(r);s!==-1&&(n.splice(s,1),n.length===1&&(this._parentOrParents=n[0]))}}};
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
+ };