@juulsgaard/signal-tools 18.0.0 → 18.0.2

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 (33) hide show
  1. package/dist/async.mjs +96 -0
  2. package/dist/data-structures/signal-map.mjs +134 -0
  3. package/dist/data-structures/signal-queue.js +115 -0
  4. package/dist/data-structures/signal-queue.mjs +115 -0
  5. package/dist/data-structures/signal-set.mjs +143 -0
  6. package/dist/data-structures/signal-stack.js +90 -0
  7. package/dist/data-structures/signal-stack.mjs +90 -0
  8. package/dist/index.d.ts +564 -62
  9. package/dist/index.js +12 -1
  10. package/dist/index.mjs +16 -0
  11. package/dist/interop.mjs +11 -0
  12. package/dist/loading-signal.mjs +68 -0
  13. package/dist/operators.js +13 -0
  14. package/dist/operators.mjs +13 -0
  15. package/dist/request-state/async-request-state.js +48 -0
  16. package/dist/request-state/async-request-state.mjs +48 -0
  17. package/dist/request-state/constructors.js +25 -0
  18. package/dist/request-state/constructors.mjs +25 -0
  19. package/dist/request-state/empty-request-state.js +20 -0
  20. package/dist/request-state/empty-request-state.mjs +20 -0
  21. package/dist/request-state/error-request-state.js +20 -0
  22. package/dist/request-state/error-request-state.mjs +20 -0
  23. package/dist/request-state/loading-request-state.js +25 -0
  24. package/dist/request-state/loading-request-state.mjs +25 -0
  25. package/dist/request-state/request-state.js +39 -0
  26. package/dist/request-state/request-state.mjs +39 -0
  27. package/dist/request-state/request-tracker.js +64 -0
  28. package/dist/request-state/request-tracker.mjs +64 -0
  29. package/dist/request-state/static-request-state.js +32 -0
  30. package/dist/request-state/static-request-state.mjs +32 -0
  31. package/dist/request-state/writable-request-state.js +75 -0
  32. package/dist/request-state/writable-request-state.mjs +75 -0
  33. package/package.json +12 -11
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
+ import * as _angular_core from '@angular/core';
1
2
  import { Signal, Injector } from '@angular/core';
2
- import { BehaviorSubject, Subject, Subscribable } from 'rxjs';
3
+ import * as rxjs from 'rxjs';
4
+ import { BehaviorSubject, Subject, Subscribable, Observable, Observer, Unsubscribable } from 'rxjs';
3
5
  import { IValueLoadingState } from '@juulsgaard/rxjs-tools';
4
6
 
5
7
  /**
@@ -62,15 +64,16 @@ declare function subjectToSignal<T>(subject: BehaviorSubject<T>): Signal<T>;
62
64
  */
63
65
  declare function subjectToSignal<T>(subject: Subject<T>, initial: T): Signal<T>;
64
66
 
65
- /** @category Loading Signal */
66
- type LoadingSignal<T> = Signal<T | undefined> & {
67
+ interface LoadingSignalProps {
67
68
  /** The current error state */
68
69
  readonly error: Signal<Error | undefined>;
69
70
  /** The current loading state */
70
71
  readonly loading: Signal<boolean>;
71
72
  /** Dispose the underlying request / action */
72
73
  readonly dispose: () => void;
73
- };
74
+ }
75
+ /** @category Loading Signal */
76
+ type LoadingSignal<T> = Signal<T | undefined> & LoadingSignalProps;
74
77
  /**
75
78
  * Options for creating a LoadingSignal
76
79
  * @category Loading Signal
@@ -120,6 +123,86 @@ declare function toLoadingSignal<T>(observable: Subscribable<T>, options?: Loadi
120
123
  */
121
124
  declare function toLoadingSignal<T>(promise: Promise<T>, options?: LoadingSignalOptions): LoadingSignal<T>;
122
125
 
126
+ /**
127
+ * A Map where the state and values are accessible as signals
128
+ * @category Signal Collections
129
+ */
130
+ declare class SignalMap<TKey, TVal> implements ReadonlySignalMap<TKey, TVal> {
131
+ private readonly _map;
132
+ /** @inheritDoc */
133
+ readonly value: Signal<ReadonlyMap<TKey, TVal>>;
134
+ /** @inheritDoc */
135
+ readonly size: Signal<number>;
136
+ /** @inheritDoc */
137
+ readonly empty: Signal<boolean>;
138
+ constructor(values?: ReadonlyMap<TKey, TVal>);
139
+ [Symbol.iterator](): IterableIterator<[TKey, TVal]>;
140
+ private getCopy;
141
+ /**
142
+ * Remove all keys not in the whitelist
143
+ * @param whitelist - The keys to keep
144
+ */
145
+ filter(whitelist: ReadonlyArray<TKey> | ReadonlySet<TKey> | undefined): boolean;
146
+ /** Clear the collection */
147
+ clear(): boolean;
148
+ /**
149
+ * Add a value to the collection if the key is not in use
150
+ * @param key - The key to use
151
+ * @param value - The value to add
152
+ * @return added - Returns true if the value was added
153
+ */
154
+ add(key: TKey, value: TVal): boolean;
155
+ /**
156
+ * Add a value to the collection
157
+ * @param key - The key to use
158
+ * @param value - The value to add
159
+ * @return added - Returns true if the value was added or changed
160
+ */
161
+ set(key: TKey, value: TVal): boolean;
162
+ /**
163
+ * Remove a key from the collection
164
+ * @param key - The key to remove
165
+ * @return removed - True if an item was removed
166
+ */
167
+ delete(key: TKey): boolean;
168
+ /**
169
+ * Remove keys from the collection
170
+ * @param values - The keys to remove
171
+ * @return removed - True if items were removed
172
+ */
173
+ deleteRange(values: TKey[]): boolean;
174
+ /**
175
+ * Toggle a value in the map
176
+ * @param key - The key to toggle
177
+ * @param value - The value to insert if applicable
178
+ * @param state - A forced state (`true` = always add, `false` = always delete)
179
+ * @returns The applied change (`true` = item added, `false` = item removed, `undefined` = nothing changed)
180
+ */
181
+ toggle(key: TKey, value: TVal, state?: boolean): boolean | undefined;
182
+ /** Manually modify the inner collection */
183
+ modify(modify: (map: Map<TKey, TVal>) => void): void;
184
+ /** @inheritDoc */
185
+ has(key: TKey): Signal<boolean>;
186
+ /** @inheritDoc */
187
+ get(key: TKey): Signal<TVal | undefined>;
188
+ }
189
+ /**
190
+ * An immutable Map where the state and values are accessible as signals
191
+ * @category Signal Collections
192
+ */
193
+ interface ReadonlySignalMap<TKey, TVal> extends Iterable<[TKey, TVal]> {
194
+ /** A signal emitting the number of items in the collection */
195
+ readonly size: Signal<number>;
196
+ /** A signal emitting true if the collection is empty */
197
+ readonly empty: Signal<boolean>;
198
+ /** A signal emitting the inner non-signal map */
199
+ readonly value: Signal<ReadonlyMap<TKey, TVal>>;
200
+ /** Create a signal emitting true if a key exists in the collection */
201
+ has(key: TKey): Signal<boolean>;
202
+ /** Create a signal emitting the value under a given key */
203
+ get(key: TKey): Signal<TVal | undefined>;
204
+ }
205
+
123
206
  /**
124
207
  * A Set where the state and values are accessible as signals
125
208
  * @category Signal Collections
@@ -205,83 +288,502 @@ interface ReadonlySignalSet<T> extends Iterable<T> {
205
288
  }
206
289
 
207
290
  /**
208
- * A Map where the state and values are accessible as signals
291
+ * A signal FIFO queue
209
292
  * @category Signal Collections
210
293
  */
211
- declare class SignalMap<TKey, TVal> implements ReadonlySignalMap<TKey, TVal> {
212
- private readonly _map;
213
- /** @inheritDoc */
214
- readonly value: Signal<ReadonlyMap<TKey, TVal>>;
215
- /** @inheritDoc */
216
- readonly size: Signal<number>;
217
- /** @inheritDoc */
294
+ declare class SignalQueue<T> {
295
+ private readonly _items;
296
+ /** A signal emitting the items of the queue */
297
+ readonly items: Signal<T[]>;
298
+ /** A signal emitting the number of items in the queue */
299
+ readonly length: Signal<number>;
300
+ /** A signal emitting true if there are no items in the queue */
218
301
  readonly empty: Signal<boolean>;
219
- constructor(values?: ReadonlyMap<TKey, TVal>);
220
- [Symbol.iterator](): IterableIterator<[TKey, TVal]>;
221
- private getCopy;
302
+ private _maxSize;
303
+ /** The max size of the queue */
304
+ get maxSize(): number | undefined;
305
+ constructor(options?: SignalQueueOptions);
222
306
  /**
223
- * Remove all keys not in the whitelist
224
- * @param whitelist - The keys to keep
307
+ * Signal returning the element at the front of the queue
225
308
  */
226
- filter(whitelist: ReadonlyArray<TKey> | ReadonlySet<TKey> | undefined): boolean;
227
- /** Clear the collection */
228
- clear(): boolean;
309
+ readonly front: Signal<T | undefined>;
310
+ /** Signal returning the current front element and whether it was just added */
311
+ readonly frontDelta: Signal<SignalQueueDelta<T>>;
229
312
  /**
230
- * Add a value to the collection if the key is not in use
231
- * @param key - The key to use
232
- * @param value - The value to add
233
- * @return added - Returns true if the value was added
313
+ * Signal returning the element at the back of the queue
234
314
  */
235
- add(key: TKey, value: TVal): boolean;
315
+ readonly back: Signal<T | undefined>;
316
+ /** Signal returning the current back element and whether it was just added */
317
+ readonly backDelta: Signal<SignalQueueDelta<T>>;
236
318
  /**
237
- * Add a value to the collection
238
- * @param key - The key to use
239
- * @param value - The value to add
240
- * @return added - Returns true if the value was added or changed
319
+ * Removes an item from the scheduler
320
+ * @param item
241
321
  */
242
- set(key: TKey, value: TVal): boolean;
322
+ removeItem(item: T): boolean;
243
323
  /**
244
- * Remove a key from the collection
245
- * @param key - The key to remove
246
- * @return removed - True if an item was removed
324
+ * Remove the front element from the queue and return it
247
325
  */
248
- delete(key: TKey): boolean;
326
+ dequeue(): T | undefined;
249
327
  /**
250
- * Remove keys from the collection
251
- * @param values - The keys to remove
252
- * @return removed - True if items were removed
328
+ * Remove the front x elements from the queue and return them
329
+ * @param count - The amount of elements to remove
253
330
  */
254
- deleteRange(values: TKey[]): boolean;
331
+ dequeue(count: number): T[];
255
332
  /**
256
- * Toggle a value in the map
257
- * @param key - The key to toggle
258
- * @param value - The value to insert if applicable
259
- * @param state - A forced state (`true` = always add, `false` = always delete)
260
- * @returns The applied change (`true` = item added, `false` = item removed, `undefined` = nothing changed)
333
+ * Remove the back element from the queue and return it
261
334
  */
262
- toggle(key: TKey, value: TVal, state?: boolean): boolean | undefined;
263
- /** Manually modify the inner collection */
264
- modify(modify: (map: Map<TKey, TVal>) => void): void;
265
- /** @inheritDoc */
266
- has(key: TKey): Signal<boolean>;
267
- /** @inheritDoc */
268
- get(key: TKey): Signal<TVal | undefined>;
335
+ removeFromBack(): T | undefined;
336
+ /**
337
+ * Remove the back x elements from the queue and return it
338
+ * @param count - The amount of elements to remove
339
+ */
340
+ removeFromBack(count: number): T[];
341
+ /**
342
+ * Add item to the back of the queue
343
+ * @param item - Item to add
344
+ */
345
+ enqueue(item: T): void;
346
+ /**
347
+ * Add items to the back of the queue
348
+ * @param items - Items to add
349
+ */
350
+ enqueue(...items: T[]): void;
351
+ /**
352
+ * Add item to the front of the queue
353
+ * @param item - Item to add
354
+ */
355
+ addToFront(item: T): void;
356
+ /**
357
+ * Add items to the front of the queue
358
+ * @param items - Items to add
359
+ */
360
+ addToFront(...items: T[]): void;
361
+ /**
362
+ * Checks if the item exists in the queue
363
+ * @param item
364
+ */
365
+ contains(item: T): boolean;
366
+ /**
367
+ * Remove all elements from the set
368
+ */
369
+ clear(): void;
370
+ /**
371
+ * Change the max size of the queue
372
+ * @param size - The new max size
373
+ */
374
+ setMaxSize(size: number | undefined): void;
269
375
  }
270
376
  /**
271
- * An immutable Map where the state and values are accessible as signals
377
+ * Options for creating a Queue
272
378
  * @category Signal Collections
273
379
  */
274
- interface ReadonlySignalMap<TKey, TVal> extends Iterable<[TKey, TVal]> {
275
- /** A signal emitting the number of items in the collection */
276
- readonly size: Signal<number>;
277
- /** A signal emitting true if the collection is empty */
380
+ interface SignalQueueOptions {
381
+ size?: number | undefined;
382
+ }
383
+ /**
384
+ * Data indicating the change in state for a location in the Queue
385
+ * @category Signal Collections
386
+ */
387
+ interface SignalQueueDelta<T> {
388
+ added: boolean;
389
+ item?: T;
390
+ }
391
+
392
+ /**
393
+ * A signal based FILO stack
394
+ * @category Signal Collections
395
+ */
396
+ declare class SignalStack<T> {
397
+ private readonly _items;
398
+ /** A signal containing the items of the stack from bottom to top */
399
+ readonly items: Signal<T[]>;
400
+ /** A signal emitting the number of items in the stack */
401
+ readonly length: Signal<number>;
402
+ /** A signal emitting true if there are no items in the stack */
278
403
  readonly empty: Signal<boolean>;
279
- /** A signal emitting the inner non-signal map */
280
- readonly value: Signal<ReadonlyMap<TKey, TVal>>;
281
- /** Create a signal emitting true if a key exists in the collection */
282
- has(key: TKey): Signal<boolean>;
283
- /** Create a signal emitting the value under a given key */
284
- get(key: TKey): Signal<TVal | undefined>;
404
+ constructor();
405
+ /** Signal returning the element at the top of the stack */
406
+ readonly top: Signal<T | undefined>;
407
+ /** Signal returning the current top element and whether it was just added */
408
+ readonly topDelta: Signal<SignalStackDelta<T>>;
409
+ /** Signal returning the element at the bottom of the stack */
410
+ readonly bottom: Signal<T | undefined>;
411
+ /** Signal returning the current bottom element and whether it was just added */
412
+ readonly bottomDelta: Signal<SignalStackDelta<T>>;
413
+ /**
414
+ * Removes an item from the scheduler
415
+ * @param item
416
+ */
417
+ removeItem(item: T): boolean;
418
+ /**
419
+ * Remove the bottom element from the stack and return it
420
+ */
421
+ removeFromBottom(): T | undefined;
422
+ /**
423
+ * Remove the bottom x elements from the stack and return them
424
+ * @param count - The amount of elements to remove
425
+ */
426
+ removeFromBottom(count: number): T[];
427
+ /**
428
+ * Remove the top element from the stack and return it
429
+ */
430
+ pop(): T | undefined;
431
+ /**
432
+ * Remove the top x elements from the stack and return it
433
+ * @param count - The amount of elements to remove
434
+ */
435
+ pop(count: number): T[];
436
+ /**
437
+ * Add item to the top of the stack
438
+ * @param item - Item to add
439
+ */
440
+ push(item: T): void;
441
+ /**
442
+ * Add items to the top of the stack
443
+ * @param items - Items to add
444
+ */
445
+ push(...items: T[]): void;
446
+ /**
447
+ * Add item to the bottom of the stack
448
+ * @param item - Item to add
449
+ */
450
+ addToBottom(item: T): void;
451
+ /**
452
+ * Add items to the bottom of the stack
453
+ * @param items - Items to add
454
+ */
455
+ addToBottom(...items: T[]): void;
456
+ /**
457
+ * Checks if the item exists in the queue
458
+ * @param item
459
+ */
460
+ contains(item: T): boolean;
461
+ /**
462
+ * Remove all elements from the set
463
+ */
464
+ clear(): void;
465
+ }
466
+ /**
467
+ * Data indicating the change in state for a location in the Stack
468
+ * @category Signal Collections
469
+ */
470
+ interface SignalStackDelta<T> {
471
+ item?: T;
472
+ added: boolean;
473
+ }
474
+
475
+ /**
476
+ * A class representing the state of a request
477
+ * @category RequestState
478
+ */
479
+ declare abstract class IRequestState implements Subscribable<unknown> {
480
+ /** The underlying request */
481
+ abstract readonly request$: Observable<unknown>;
482
+ /** The result of the request */
483
+ abstract readonly result$: Observable<unknown>;
484
+ /** The result of the request, or undefined when unresolved */
485
+ abstract readonly result: Signal<unknown | undefined>;
486
+ /** Emits true when the request is running */
487
+ abstract readonly loading: Signal<boolean>;
488
+ /** Emits the error if one is thrown by the request. Otherwise undefined */
489
+ abstract readonly error: Signal<Error | undefined>;
490
+ /** Emits true if the request failed */
491
+ abstract readonly failed: Signal<boolean>;
492
+ /** Cancel a running request */
493
+ abstract cancel(): boolean;
494
+ /**
495
+ * Perform actions when the request finishes
496
+ * @param onValue - Action to perform on successful resolution
497
+ * @param onError - Action to perform on error
498
+ */
499
+ abstract then(onValue: (value: unknown) => void, onError?: (error: Error) => void): this;
500
+ /**
501
+ * Perform an action if the request fails
502
+ * @param onError
503
+ */
504
+ abstract catch(onError: (error: Error) => void): this;
505
+ /**
506
+ * Perform an action when the request finishes (Error or Success)
507
+ * @param onComplete
508
+ */
509
+ abstract finally(onComplete: (error?: Error) => void): this;
510
+ /**
511
+ * Subscribe to the underlying request Observable
512
+ * @param observer
513
+ */
514
+ subscribe(observer: Partial<Observer<unknown>>): Unsubscribable;
515
+ }
516
+ /**
517
+ * A class representing the state of a request with a known return type
518
+ * @category RequestState
519
+ */
520
+ declare abstract class IValueRequestState<T> extends IRequestState implements Subscribable<T> {
521
+ abstract readonly request$: Observable<T>;
522
+ abstract readonly result$: Observable<T>;
523
+ abstract readonly result: Signal<T | undefined>;
524
+ subscribe(observer: Partial<Observer<T>>): Unsubscribable;
525
+ then(onValue: (value: T) => void, onError?: (error: Error) => void): this;
526
+ catch(onError: (error: Error) => void): this;
527
+ finally(onComplete: (error?: Error) => void): this;
528
+ /**
529
+ * Cancel a running request
530
+ * @param error - Optionally provide a custom error to throw when cancelling the request
531
+ */
532
+ abstract cancel(error?: string | Error | (() => Error)): boolean;
533
+ }
534
+
535
+ /**
536
+ * A manually populated RequestState
537
+ * @category RequestState
538
+ */
539
+ declare class WritableRequestState<T> extends IValueRequestState<T> {
540
+ private readonly onCancel?;
541
+ private _completed;
542
+ get completed(): boolean;
543
+ private readonly _request$;
544
+ readonly request$: rxjs.Observable<T>;
545
+ private readonly _result$;
546
+ readonly result$: rxjs.Observable<T>;
547
+ private readonly _result;
548
+ readonly result: _angular_core.Signal<T | undefined>;
549
+ private readonly _loading;
550
+ readonly loading: _angular_core.Signal<boolean>;
551
+ private readonly _error;
552
+ readonly error: _angular_core.Signal<Error | undefined>;
553
+ readonly failed: _angular_core.Signal<boolean>;
554
+ private readonly _cancelled;
555
+ /** Emits true when the RequestState has been cancelled by a consumer, otherwise emits false */
556
+ readonly cancelled: _angular_core.Signal<boolean>;
557
+ private readonly _cancelled$;
558
+ /** Emits true when the RequestState has been cancelled by a consumer */
559
+ readonly cancelled$: rxjs.Observable<true>;
560
+ constructor(onCancel?: (() => void) | undefined);
561
+ /**
562
+ * Create a Readonly version of the RequestState
563
+ */
564
+ asReadonly(): IValueRequestState<T>;
565
+ /**
566
+ * Set the RequestState to an Error state
567
+ * @param error - The error for the RequestState
568
+ */
569
+ setError(error: unknown | Error): void;
570
+ /**
571
+ * Set the RequestState to a completed state with a given value
572
+ * @param value - The value to emit
573
+ */
574
+ setValue(value: T): void;
575
+ cancel(error?: string | Error | (() => Error)): boolean;
576
+ }
577
+
578
+ /**
579
+ * Create a RequestState from a request or Value
580
+ * @param data - The request or value
581
+ * @category RequestState
582
+ */
583
+ declare function valueRequestState<T>(data: T | Promise<T> | Observable<T>): IValueRequestState<T>;
584
+ /** @category RequestState */
585
+ interface AltConstructors {
586
+ /**
587
+ * Create a writable RequestState
588
+ * @param onCancel - Optional cancellation handler
589
+ * @category RequestState
590
+ */
591
+ writable<T>(onCancel?: () => void): WritableRequestState<T>;
592
+ /**
593
+ * Create a RequestState emitting an error
594
+ * @param error - The error to emit
595
+ * @category RequestState
596
+ */
597
+ error(error: Error | (() => Error)): IRequestState;
598
+ /**
599
+ * Create a typed RequestState emitting an error
600
+ * @param error - The error to emit
601
+ * @category RequestState
602
+ */
603
+ error<T>(error: Error | (() => Error)): IValueRequestState<T>;
604
+ /**
605
+ * Create a RequestState which is always loading
606
+ * @category RequestState
607
+ */
608
+ loading(): IRequestState;
609
+ /**
610
+ * Create a typed RequestState which is always loading
611
+ * @category RequestState
612
+ */
613
+ loading<T>(): IValueRequestState<T>;
614
+ /**
615
+ * Create a RequestState that resolves after an amount of time
616
+ * @param duration - The loading duration in milliseconds
617
+ * @category RequestState
618
+ */
619
+ loading(duration: number): IRequestState;
620
+ /**
621
+ * Create a RequestState that resolves with a value after an amount of time
622
+ * @param duration - The loading duration in milliseconds
623
+ * @param value - The value to resolve with after the delay
624
+ * @category RequestState
625
+ */
626
+ loading<T>(duration: number, value: T): IValueRequestState<T>;
627
+ /**
628
+ * Create an empty RequestState
629
+ * @category RequestState
630
+ */
631
+ empty(): IRequestState;
632
+ /**
633
+ * Create a typed empty RequestState
634
+ * @category RequestState
635
+ */
636
+ empty<T>(): IValueRequestState<T>;
285
637
  }
638
+ declare const requestState: typeof valueRequestState & AltConstructors;
639
+
640
+ /**
641
+ * A RequestState representing a pending async action
642
+ * @category RequestState
643
+ */
644
+ declare class AsyncRequestState<T> extends IValueRequestState<T> {
645
+ private readonly _request$;
646
+ readonly request$: Observable<T>;
647
+ private readonly _result$;
648
+ readonly result$: Observable<T>;
649
+ private readonly _result;
650
+ readonly result: _angular_core.Signal<T | undefined>;
651
+ private readonly _loading;
652
+ readonly loading: _angular_core.Signal<boolean>;
653
+ private readonly _error;
654
+ readonly error: _angular_core.Signal<Error | undefined>;
655
+ readonly failed: _angular_core.Signal<boolean>;
656
+ private readonly sub;
657
+ constructor(request: Promise<T> | Observable<T>);
658
+ cancel(error?: string | Error | (() => Error)): boolean;
659
+ }
660
+
661
+ /**
662
+ * An Empty RequestState
663
+ * @category RequestState
664
+ */
665
+ declare class EmptyRequestState<T> extends IValueRequestState<T> {
666
+ readonly request$: rxjs.Observable<never>;
667
+ readonly result$: rxjs.Observable<never>;
668
+ readonly result: Signal<undefined>;
669
+ readonly loading: Signal<false>;
670
+ readonly error: Signal<undefined>;
671
+ readonly failed: Signal<false>;
672
+ cancel(): boolean;
673
+ }
674
+
675
+ /**
676
+ * A RequestState which always emits an error
677
+ * @category RequestState
678
+ */
679
+ declare class ErrorRequestState<T> extends IValueRequestState<T> {
680
+ readonly request$: Observable<never>;
681
+ readonly result$: Observable<never>;
682
+ readonly result: Signal<undefined>;
683
+ readonly loading: Signal<boolean>;
684
+ readonly error: Signal<Error | undefined>;
685
+ readonly failed: Signal<boolean>;
686
+ constructor(getError: () => Error);
687
+ cancel(): boolean;
688
+ }
689
+
690
+ /**
691
+ * A RequestState which is perpetually loading
692
+ * @category RequestState
693
+ */
694
+ declare class LoadingRequestState<T> extends IValueRequestState<T> {
695
+ private readonly _request$;
696
+ readonly request$: rxjs.Observable<T>;
697
+ readonly result$: rxjs.Observable<T>;
698
+ readonly result: Signal<undefined>;
699
+ private readonly _loading;
700
+ readonly loading: Signal<boolean>;
701
+ readonly error: Signal<undefined>;
702
+ readonly failed: Signal<false>;
703
+ cancel(): boolean;
704
+ }
705
+
706
+ /**
707
+ * A RequestState which always returns the same value immediately
708
+ * @category RequestState
709
+ */
710
+ declare class StaticRequestState<T> extends IValueRequestState<T> {
711
+ private readonly value;
712
+ readonly request$: Observable<T>;
713
+ readonly result$: Observable<T>;
714
+ readonly result: Signal<T>;
715
+ readonly loading: Signal<false>;
716
+ readonly error: Signal<undefined>;
717
+ readonly failed: Signal<false>;
718
+ constructor(value: T);
719
+ cancel(): boolean;
720
+ then(next: (value: T) => void, _error?: (error: Error) => void): this;
721
+ catch(_onError: (error: Error) => void): this;
722
+ finally(onComplete: () => void): this;
723
+ }
724
+
725
+ /**
726
+ * A container which keeps track of a replaceable RequestState
727
+ * @category RequestState
728
+ */
729
+ declare class RequestTracker {
730
+ private readonly _request;
731
+ /** The currently active RequestState */
732
+ readonly request: Signal<IRequestState>;
733
+ /** The currently active RequestState */
734
+ set current(req: IRequestState);
735
+ get current(): IRequestState;
736
+ /** Emits true if the current RequestState is loading */
737
+ readonly loading: Signal<boolean>;
738
+ /** Emits an error if the current RequestState is in an error state */
739
+ readonly error: Signal<Error | undefined>;
740
+ /** Emits true if the current RequestState has failed */
741
+ readonly failed: Signal<boolean>;
742
+ constructor(request?: IRequestState);
743
+ /**
744
+ * Set a new current RequestState
745
+ * @param state - The new RequestState
746
+ */
747
+ set(state: IRequestState): void;
748
+ /**
749
+ * Resets the Tracker to an Empty state
750
+ */
751
+ reset(): void;
752
+ }
753
+ /**
754
+ * A container which keeps track of a replaceable RequestState of a known return type
755
+ * @category RequestState
756
+ */
757
+ declare class ValueRequestTracker<T> extends RequestTracker {
758
+ private readonly _valueRequest;
759
+ request: Signal<IValueRequestState<T>>;
760
+ set current(req: IValueRequestState<T>);
761
+ get current(): IValueRequestState<T>;
762
+ constructor(request?: IValueRequestState<T>);
763
+ set(req: IValueRequestState<T>): void;
764
+ reset(): void;
765
+ }
766
+ /**
767
+ * Create an empty and untyped RequestTracker
768
+ * @category RequestState
769
+ */
770
+ declare function requestTracker(): RequestTracker;
771
+ /**
772
+ * Create an empty RequestTracker with a known RequestState return type
773
+ * @category RequestState
774
+ */
775
+ declare function requestTracker<T>(): ValueRequestTracker<T>;
776
+ /**
777
+ * Create a typed RequestTracker from a types RequestState
778
+ * @param request - The initial RequestState
779
+ * @category RequestState
780
+ */
781
+ declare function requestTracker<T>(request: IValueRequestState<T>): ValueRequestTracker<T>;
782
+ /**
783
+ * Create an untyped RequestTracker from an untyped RequestState
784
+ * @param request - The initial RequestState
785
+ * @category RequestState
786
+ */
787
+ declare function requestTracker(request: IRequestState): RequestTracker;
286
788
 
287
- export { type CreateLoadingSignalOptions, type LoadingSignal, type LoadingSignalOptions, type ReadonlySignalMap, type ReadonlySignalSet, SignalMap, SignalSet, debouncedSignal, debouncedThrottledSignal, loadingSignal, searchSignal, subjectToSignal, throttledSignal, toLoadingSignal };
789
+ export { AsyncRequestState, type CreateLoadingSignalOptions, EmptyRequestState, ErrorRequestState, IRequestState, IValueRequestState, LoadingRequestState, type LoadingSignal, type LoadingSignalOptions, type ReadonlySignalMap, type ReadonlySignalSet, RequestTracker, SignalMap, SignalQueue, type SignalQueueDelta, type SignalQueueOptions, SignalSet, SignalStack, type SignalStackDelta, StaticRequestState, ValueRequestTracker, WritableRequestState, debouncedSignal, debouncedThrottledSignal, loadingSignal, requestState, requestTracker, searchSignal, subjectToSignal, throttledSignal, toLoadingSignal };