@dereekb/rxjs 13.43.0 → 14.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.esm.js +615 -416
- package/package.json +2 -2
- package/src/lib/iterator/iteration.accumulator.d.ts +10 -10
- package/src/lib/iterator/iteration.d.ts +2 -2
- package/src/lib/iterator/iteration.mapped.d.ts +6 -6
- package/src/lib/iterator/iteration.mapped.page.d.ts +3 -3
- package/src/lib/iterator/iteration.next.d.ts +1 -1
- package/src/lib/iterator/iterator.page.d.ts +1 -1
- package/src/lib/loading/loading.context.state.list.d.ts +8 -8
- package/src/lib/loading/loading.state.d.ts +169 -56
- package/src/lib/loading/loading.state.list.d.ts +3 -3
- package/src/lib/loading/loading.state.rxjs.d.ts +37 -52
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Maybe, type ReadableError, type ReadableDataError, type Page, type
|
|
1
|
+
import { type Maybe, type ReadableError, type ReadableDataError, type Page, type PageNumber, type MapFunction, type ErrorInput } from '@dereekb/util';
|
|
2
2
|
import { type LoadingProgress } from './loading';
|
|
3
3
|
/**
|
|
4
4
|
* A value/error pair used in loading situations.
|
|
@@ -36,7 +36,7 @@ export interface LoadingErrorPair {
|
|
|
36
36
|
* isLoadingStateEqual(a, c); // false
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
export declare function isLoadingStateEqual<
|
|
39
|
+
export declare function isLoadingStateEqual<L extends LoadingState>(a: L, b: L): boolean;
|
|
40
40
|
/**
|
|
41
41
|
* Compares the metadata (loading flag, loading progress, and error) of two {@link LoadingErrorPair} instances,
|
|
42
42
|
* using loose equality for loading and nullish-aware comparison for progress and error.
|
|
@@ -50,18 +50,43 @@ export declare function isLoadingStateEqual<T extends LoadingState>(a: T, b: T):
|
|
|
50
50
|
export declare function isLoadingStateMetadataEqual(a: Partial<LoadingErrorPair>, b: Partial<LoadingErrorPair>): boolean;
|
|
51
51
|
/**
|
|
52
52
|
* A value/error pair used in loading situations.
|
|
53
|
+
*
|
|
54
|
+
* The `T = unknown` default is deliberate: it makes the bare `LoadingState` the correct top type for
|
|
55
|
+
* an `L extends LoadingState` constraint, which every shape-preserving helper in this file relies on.
|
|
53
56
|
*/
|
|
54
57
|
export interface LoadingState<T = unknown> extends LoadingErrorPair {
|
|
55
58
|
readonly value?: Maybe<T>;
|
|
56
59
|
}
|
|
57
60
|
/**
|
|
58
61
|
* Returns the value type inferred from the LoadingState type.
|
|
62
|
+
*
|
|
63
|
+
* This is a conditional type, and therefore a non-inferable position: a signature that mentions
|
|
64
|
+
* `LoadingStateValue<L>` in an argument position can never infer `L` from that argument. Use it only
|
|
65
|
+
* in callback-parameter positions and return types.
|
|
66
|
+
*
|
|
67
|
+
* Note that `LoadingStateValue<LoadingState<never>>` resolves to `unknown`, not `never`, because
|
|
68
|
+
* inferring `Maybe<never>` (which is `null | undefined`) against `Maybe<T>` leaves `T` candidate-less.
|
|
69
|
+
*
|
|
70
|
+
* The conditional `infer` body is kept intentionally; a `NonNullable<L['value']>` rewrite is
|
|
71
|
+
* functionally equivalent and removes no cast.
|
|
59
72
|
*/
|
|
60
73
|
export type LoadingStateValue<L extends LoadingState> = L extends LoadingState<infer T> ? T : never;
|
|
61
74
|
/**
|
|
62
75
|
* Replaces the value type of the input LoadingState.
|
|
76
|
+
*
|
|
77
|
+
* The `L extends LoadingState ? ... : never` wrapper is load-bearing rather than dead code: it makes
|
|
78
|
+
* the type distribute over a union of state types. `Omit<A | B, K>` collapses a union down to its
|
|
79
|
+
* common keys, so without distribution a union containing a {@link PageLoadingState} would lose `page`.
|
|
63
80
|
*/
|
|
64
81
|
export type LoadingStateWithValueType<L extends LoadingState, T> = L extends LoadingState ? Omit<L, 'value'> & LoadingState<T> : never;
|
|
82
|
+
/**
|
|
83
|
+
* The result of re-deriving a {@link LoadingState} with its `value` and `error` cleared or replaced.
|
|
84
|
+
*
|
|
85
|
+
* The `value` and `error` keys are dropped from `S` before the plain {@link LoadingState} shape is
|
|
86
|
+
* re-added, because the merge helpers may clear a field that `S` itself requires (a
|
|
87
|
+
* `LoadingStateWithDefinedValue<Foo>` cannot honestly be returned once its value is cleared).
|
|
88
|
+
*/
|
|
89
|
+
export type MergedLoadingState<S extends LoadingState> = Omit<S, 'value' | 'error'> & LoadingState<LoadingStateValue<S>>;
|
|
65
90
|
/**
|
|
66
91
|
* Loading state with a value key.
|
|
67
92
|
*/
|
|
@@ -93,19 +118,10 @@ export interface PageLoadingState<T = unknown> extends LoadingState<T>, Page {
|
|
|
93
118
|
*/
|
|
94
119
|
readonly hasNextPage?: Maybe<boolean>;
|
|
95
120
|
}
|
|
96
|
-
/**
|
|
97
|
-
* PageLoadingState with a filter.
|
|
98
|
-
*/
|
|
99
|
-
export interface FilteredPageLoadingState<T, F> extends PageLoadingState<T>, FilteredPage<F> {
|
|
100
|
-
}
|
|
101
121
|
/**
|
|
102
122
|
* LoadingPageState that has an array of the values and
|
|
103
123
|
*/
|
|
104
|
-
export type PageListLoadingState<T> = PageLoadingState<T[]>;
|
|
105
|
-
/**
|
|
106
|
-
* PageListLoadingState with a Filter.
|
|
107
|
-
*/
|
|
108
|
-
export type FilteredPageListLoadingState<T, F> = FilteredPageLoadingState<T[], F>;
|
|
124
|
+
export type PageListLoadingState<T = unknown> = PageLoadingState<T[]>;
|
|
109
125
|
/**
|
|
110
126
|
* Describes a LoadingState's current state type.
|
|
111
127
|
*/
|
|
@@ -177,7 +193,7 @@ export declare function isLoadingStateFinishedLoading<L extends LoadingState>(st
|
|
|
177
193
|
* loadingStateType(state); // LoadingStateType.IDLE
|
|
178
194
|
* ```
|
|
179
195
|
*/
|
|
180
|
-
export declare function idleLoadingState<T>(): LoadingState<T>;
|
|
196
|
+
export declare function idleLoadingState<T = never>(): LoadingState<T>;
|
|
181
197
|
/**
|
|
182
198
|
* Creates a {@link LoadingState} with `loading: true`, optionally merged with additional state properties.
|
|
183
199
|
*
|
|
@@ -193,9 +209,9 @@ export declare function idleLoadingState<T>(): LoadingState<T>;
|
|
|
193
209
|
* @param state - optional partial state to merge with the loading flag
|
|
194
210
|
* @returns a loading state with `loading: true`
|
|
195
211
|
*/
|
|
196
|
-
export declare function beginLoading<T>(): LoadingState<T>;
|
|
197
|
-
export declare function beginLoading<T>(state
|
|
198
|
-
export declare function beginLoading<T>(state?: Partial<LoadingState<T>>): LoadingState<T>;
|
|
212
|
+
export declare function beginLoading<T = never>(): LoadingState<T>;
|
|
213
|
+
export declare function beginLoading<T = never>(state: Partial<LoadingState<T>> & Page): PageLoadingState<T>;
|
|
214
|
+
export declare function beginLoading<T = never>(state?: Partial<LoadingState<T>>): LoadingState<T>;
|
|
199
215
|
/**
|
|
200
216
|
* Creates a {@link PageLoadingState} that is loading for the given page number.
|
|
201
217
|
*
|
|
@@ -224,7 +240,7 @@ export declare function successResult<T>(value: T): LoadingStateWithValue<T>;
|
|
|
224
240
|
* @param value - The loaded value.
|
|
225
241
|
* @returns A page loading state representing success.
|
|
226
242
|
*/
|
|
227
|
-
export declare function successPageResult<T>(page: PageNumber, value: T): PageLoadingState<T>;
|
|
243
|
+
export declare function successPageResult<T>(page: PageNumber, value: T): PageLoadingState<T> & LoadingStateWithValue<T>;
|
|
228
244
|
/**
|
|
229
245
|
* Creates a {@link LoadingState} representing an error with `loading: false`.
|
|
230
246
|
*
|
|
@@ -239,7 +255,8 @@ export declare function successPageResult<T>(page: PageNumber, value: T): PageLo
|
|
|
239
255
|
* // { error: { message: 'Not found', ... }, loading: false }
|
|
240
256
|
* ```
|
|
241
257
|
*/
|
|
242
|
-
export declare function errorResult<T>(error
|
|
258
|
+
export declare function errorResult<T = never>(error: ErrorInput): LoadingStateWithError<T>;
|
|
259
|
+
export declare function errorResult<T = never>(error?: Maybe<ErrorInput>): LoadingState<T>;
|
|
243
260
|
/**
|
|
244
261
|
* Creates a {@link PageLoadingState} representing an error for a specific page.
|
|
245
262
|
*
|
|
@@ -247,7 +264,7 @@ export declare function errorResult<T>(error?: Maybe<ErrorInput>): LoadingState<
|
|
|
247
264
|
* @param error - The error to include.
|
|
248
265
|
* @returns A page loading state representing an error.
|
|
249
266
|
*/
|
|
250
|
-
export declare function errorPageResult<T>(page: PageNumber, error?: Maybe<
|
|
267
|
+
export declare function errorPageResult<T = never>(page: PageNumber, error?: Maybe<ErrorInput>): PageLoadingState<T>;
|
|
251
268
|
/**
|
|
252
269
|
* Whether any of the given {@link LoadingState} instances are currently loading.
|
|
253
270
|
*
|
|
@@ -260,7 +277,7 @@ export declare function errorPageResult<T>(page: PageNumber, error?: Maybe<Reada
|
|
|
260
277
|
* isAnyLoadingStateInLoadingState([successResult(1), successResult(2)]); // false
|
|
261
278
|
* ```
|
|
262
279
|
*/
|
|
263
|
-
export declare function isAnyLoadingStateInLoadingState(states: LoadingState[]): boolean;
|
|
280
|
+
export declare function isAnyLoadingStateInLoadingState(states: readonly LoadingState[]): boolean;
|
|
264
281
|
/**
|
|
265
282
|
* Whether all given {@link LoadingState} instances have finished loading.
|
|
266
283
|
*
|
|
@@ -273,7 +290,7 @@ export declare function isAnyLoadingStateInLoadingState(states: LoadingState[]):
|
|
|
273
290
|
* areAllLoadingStatesFinishedLoading([successResult(1), beginLoading()]); // false
|
|
274
291
|
* ```
|
|
275
292
|
*/
|
|
276
|
-
export declare function areAllLoadingStatesFinishedLoading(states: LoadingState[]): boolean;
|
|
293
|
+
export declare function areAllLoadingStatesFinishedLoading(states: readonly LoadingState[]): boolean;
|
|
277
294
|
/**
|
|
278
295
|
* Creates a predicate function that checks whether a {@link LoadingState} matches the given {@link LoadingStateType}.
|
|
279
296
|
*
|
|
@@ -328,7 +345,7 @@ export declare const isLoadingStateInErrorState: <L extends LoadingState>(state:
|
|
|
328
345
|
* isLoadingStateWithDefinedValue(beginLoading()); // false
|
|
329
346
|
* ```
|
|
330
347
|
*/
|
|
331
|
-
export declare function isLoadingStateWithDefinedValue<L extends LoadingState>(state: Maybe<L>
|
|
348
|
+
export declare function isLoadingStateWithDefinedValue<L extends LoadingState>(state: Maybe<L>): state is L & LoadingStateWithDefinedValue<LoadingStateValue<L>>;
|
|
332
349
|
/**
|
|
333
350
|
* Type guard that checks whether a {@link LoadingState} has a non-null error, regardless of loading status.
|
|
334
351
|
*
|
|
@@ -341,21 +358,21 @@ export declare function isLoadingStateWithDefinedValue<L extends LoadingState>(s
|
|
|
341
358
|
* isLoadingStateWithError(successResult('ok')); // false
|
|
342
359
|
* ```
|
|
343
360
|
*/
|
|
344
|
-
export declare function isLoadingStateWithError<L extends LoadingState>(state: Maybe<L>
|
|
361
|
+
export declare function isLoadingStateWithError<L extends LoadingState>(state: Maybe<L>): state is L & LoadingStateWithError<LoadingStateValue<L>>;
|
|
345
362
|
/**
|
|
346
363
|
* Type guard that checks whether a {@link LoadingState} has finished loading and has a defined value.
|
|
347
364
|
*
|
|
348
365
|
* @param state - The loading state to check.
|
|
349
366
|
* @returns True if finished loading with a non-undefined value.
|
|
350
367
|
*/
|
|
351
|
-
export declare function isLoadingStateFinishedLoadingWithDefinedValue<L extends LoadingState>(state: Maybe<L>
|
|
368
|
+
export declare function isLoadingStateFinishedLoadingWithDefinedValue<L extends LoadingState>(state: Maybe<L>): state is L & LoadingStateWithDefinedValue<LoadingStateValue<L>>;
|
|
352
369
|
/**
|
|
353
370
|
* Type guard that checks whether a {@link LoadingState} has finished loading and has an error.
|
|
354
371
|
*
|
|
355
372
|
* @param state - The loading state to check.
|
|
356
373
|
* @returns True if finished loading with an error.
|
|
357
374
|
*/
|
|
358
|
-
export declare function isLoadingStateFinishedLoadingWithError<L extends LoadingState>(state: Maybe<L>
|
|
375
|
+
export declare function isLoadingStateFinishedLoadingWithError<L extends LoadingState>(state: Maybe<L>): state is L & LoadingStateWithError<LoadingStateValue<L>>;
|
|
359
376
|
/**
|
|
360
377
|
* Compares the metadata (page, loading, error) of two {@link PageLoadingState} instances for equivalence.
|
|
361
378
|
*
|
|
@@ -379,6 +396,73 @@ export declare function isLoadingStateFinishedLoadingWithError<L extends Loading
|
|
|
379
396
|
* ```
|
|
380
397
|
*/
|
|
381
398
|
export declare function isPageLoadingStateMetadataEqual(a: Partial<PageLoadingState>, b: Partial<PageLoadingState>): boolean;
|
|
399
|
+
/**
|
|
400
|
+
* Type guard that checks whether the input {@link LoadingState} also carries a {@link Page}.
|
|
401
|
+
*
|
|
402
|
+
* `Page` is intentionally kept orthogonal to `LoadingState`, so this is the supported way to ask a
|
|
403
|
+
* state whether it is paginated without hoisting page keys onto the base type.
|
|
404
|
+
*
|
|
405
|
+
* @param state - The loading state to check (may be null/undefined)
|
|
406
|
+
* @returns True when the state is present and exposes a numeric `page`.
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```ts
|
|
410
|
+
* isPageLoadingState(successPageResult(0, 'a')); // true
|
|
411
|
+
* isPageLoadingState(successResult('a')); // false
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
export declare function isPageLoadingState<L extends LoadingState>(state: Maybe<L>): state is L & Page;
|
|
415
|
+
/**
|
|
416
|
+
* Reads the `hasNextPage` flag from the input state, if it carries one.
|
|
417
|
+
*
|
|
418
|
+
* @param state - The loading state to read from (may be null/undefined)
|
|
419
|
+
* @returns The `hasNextPage` value, or null/undefined when the state is absent or not paginated.
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* ```ts
|
|
423
|
+
* loadingStateHasNextPage({ page: 0, loading: false, hasNextPage: true }); // true
|
|
424
|
+
* loadingStateHasNextPage(successResult('a')); // undefined
|
|
425
|
+
* ```
|
|
426
|
+
*/
|
|
427
|
+
export declare function loadingStateHasNextPage(state: Maybe<LoadingState>): Maybe<boolean>;
|
|
428
|
+
/**
|
|
429
|
+
* Reads the value of a generic {@link LoadingState}.
|
|
430
|
+
*
|
|
431
|
+
* Reading `state.value` where `state: L` resolves through `L`'s apparent type (its constraint), which
|
|
432
|
+
* yields `Maybe<unknown>` rather than `Maybe<LoadingStateValue<L>>`. This is the single documented
|
|
433
|
+
* site that casts that back, so no other function in the library needs to.
|
|
434
|
+
*
|
|
435
|
+
* @param state - The loading state to read the value from.
|
|
436
|
+
* @returns The state's value, typed as the state's value type.
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```ts
|
|
440
|
+
* loadingStateValue(successResult('a')); // 'a'
|
|
441
|
+
* loadingStateValue(beginLoading<string>()); // undefined
|
|
442
|
+
* ```
|
|
443
|
+
*/
|
|
444
|
+
export declare function loadingStateValue<L extends LoadingState>(state: L): Maybe<LoadingStateValue<L>>;
|
|
445
|
+
/**
|
|
446
|
+
* Copies the input state, replacing only its value, and retypes the result to match.
|
|
447
|
+
*
|
|
448
|
+
* Distinct from {@link mergeLoadingStateWithValue}, which additionally forces `loading: false` and
|
|
449
|
+
* clears any error; this preserves the input state's metadata (including `loading` and `error`)
|
|
450
|
+
* exactly and swaps the value alone.
|
|
451
|
+
*
|
|
452
|
+
* @param state - The state to copy metadata from.
|
|
453
|
+
* @param value - The replacement value.
|
|
454
|
+
* @returns The state with its value type replaced.
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* loadingStateWithValueType(successPageResult(0, 'a'), 1); // { page: 0, loading: false, value: 1 }
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
export declare function loadingStateWithValueType<L extends LoadingState, T>(state: L, value: Maybe<T>): LoadingStateWithValueType<L, T>;
|
|
462
|
+
/**
|
|
463
|
+
* Function used by {@link mergeLoadingStatesArray} to merge the values of the input states.
|
|
464
|
+
*/
|
|
465
|
+
export type MergeLoadingStatesArrayFunction<O> = (...values: any[]) => O;
|
|
382
466
|
/**
|
|
383
467
|
* Merges multiple {@link LoadingState} instances into a single combined state.
|
|
384
468
|
*
|
|
@@ -418,9 +502,30 @@ export declare function mergeLoadingStates<A extends object, B extends object, C
|
|
|
418
502
|
export declare function mergeLoadingStates<A extends object, B extends object, C extends object, O>(a: LoadingState<A>, b: LoadingState<B>, c: LoadingState<C>, mergeFn: (a: A, b: B, c: C) => O): LoadingState<O>;
|
|
419
503
|
export declare function mergeLoadingStates<A extends object, B extends object, C extends object, D extends object>(a: LoadingState<A>, b: LoadingState<B>, c: LoadingState<C>, d: LoadingState<D>): LoadingState<A & B & C & D>;
|
|
420
504
|
export declare function mergeLoadingStates<A extends object, B extends object, C extends object, D extends object, O>(a: LoadingState<A>, b: LoadingState<B>, c: LoadingState<C>, d: LoadingState<D>, mergeFn: (a: A, b: B, c: C, d: D) => O): LoadingState<O>;
|
|
421
|
-
export declare function mergeLoadingStates<A extends object, B extends object, C extends object, D extends object, E extends object
|
|
505
|
+
export declare function mergeLoadingStates<A extends object, B extends object, C extends object, D extends object, E extends object>(a: LoadingState<A>, b: LoadingState<B>, c: LoadingState<C>, d: LoadingState<D>, e: LoadingState<E>): LoadingState<A & B & C & D & E>;
|
|
422
506
|
export declare function mergeLoadingStates<A extends object, B extends object, C extends object, D extends object, E extends object, O>(a: LoadingState<A>, b: LoadingState<B>, c: LoadingState<C>, d: LoadingState<D>, e: LoadingState<E>, mergeFn: (a: A, b: B, c: C, d: D, e: E) => O): LoadingState<O>;
|
|
423
507
|
export declare function mergeLoadingStates<O>(...args: any[]): LoadingState<O>;
|
|
508
|
+
/**
|
|
509
|
+
* Merges an array of {@link LoadingState} instances into a single combined state.
|
|
510
|
+
*
|
|
511
|
+
* The non-variadic counterpart to {@link mergeLoadingStates}: because the states arrive as one array
|
|
512
|
+
* argument rather than as rest arguments, the output value type `O` is inferable from `mergeFn` and
|
|
513
|
+
* the call site needs no cast.
|
|
514
|
+
*
|
|
515
|
+
* @param states - The loading states to merge.
|
|
516
|
+
* @param mergeFn - Optional function merging the states' values; defaults to `mergeObjects`.
|
|
517
|
+
* @returns The combined loading state.
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```ts
|
|
521
|
+
* mergeLoadingStatesArray([successResult({ a: 1 }), successResult({ b: 2 })]);
|
|
522
|
+
* // { loading: false, value: { a: 1, b: 2 } }
|
|
523
|
+
*
|
|
524
|
+
* mergeLoadingStatesArray([successResult(1), successResult(2)], (a: number, b: number) => a + b);
|
|
525
|
+
* // { loading: false, value: 3 }
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
export declare function mergeLoadingStatesArray<O>(states: readonly LoadingState[], mergeFn?: MergeLoadingStatesArrayFunction<O>): LoadingState<O>;
|
|
424
529
|
/**
|
|
425
530
|
* Returns a copy of the state with the value and error cleared, and `loading` set to the given flag.
|
|
426
531
|
*
|
|
@@ -430,7 +535,7 @@ export declare function mergeLoadingStates<O>(...args: any[]): LoadingState<O>;
|
|
|
430
535
|
* @param loading - Whether to mark as loading (defaults to true)
|
|
431
536
|
* @returns A new state with value/error cleared.
|
|
432
537
|
*/
|
|
433
|
-
export declare function mergeLoadingStateWithLoading<S extends LoadingState>(state: S, loading?: boolean): S
|
|
538
|
+
export declare function mergeLoadingStateWithLoading<S extends LoadingState>(state: S, loading?: boolean): MergedLoadingState<S>;
|
|
434
539
|
/**
|
|
435
540
|
* Returns a copy of the state with the given value, `loading: false`, and error cleared.
|
|
436
541
|
*
|
|
@@ -438,7 +543,7 @@ export declare function mergeLoadingStateWithLoading<S extends LoadingState>(sta
|
|
|
438
543
|
* @param value - The new value to set.
|
|
439
544
|
* @returns A new state representing success.
|
|
440
545
|
*/
|
|
441
|
-
export declare function mergeLoadingStateWithValue<S extends LoadingState>(state: S, value: LoadingStateValue<S
|
|
546
|
+
export declare function mergeLoadingStateWithValue<S extends LoadingState>(state: S, value: Maybe<LoadingStateValue<S>>): MergedLoadingState<S>;
|
|
442
547
|
/**
|
|
443
548
|
* Returns a copy of the state with the given error and `loading: false`.
|
|
444
549
|
*
|
|
@@ -446,29 +551,33 @@ export declare function mergeLoadingStateWithValue<S extends LoadingState>(state
|
|
|
446
551
|
* @param error - The error to set.
|
|
447
552
|
* @returns A new state representing an error.
|
|
448
553
|
*/
|
|
449
|
-
export declare function mergeLoadingStateWithError<S extends LoadingState = LoadingState>(state: S, error?: ReadableDataError): S
|
|
450
|
-
export type MapMultipleLoadingStateValuesFn<T, X> = (input: X[]) => T;
|
|
451
|
-
export interface MapMultipleLoadingStateResultsConfiguration<T, X, L extends LoadingState<X>[], R extends LoadingState<T>> {
|
|
452
|
-
readonly mapValues?: MapMultipleLoadingStateValuesFn<T, X>;
|
|
453
|
-
readonly mapState?: (input: L) => R;
|
|
454
|
-
}
|
|
554
|
+
export declare function mergeLoadingStateWithError<S extends LoadingState = LoadingState>(state: S, error?: ReadableDataError): MergedLoadingState<S>;
|
|
455
555
|
/**
|
|
456
|
-
* Maps
|
|
556
|
+
* Maps an entire input {@link LoadingState} (and its already-mapped value) to the output state.
|
|
457
557
|
*
|
|
458
|
-
*
|
|
558
|
+
* State-first, per the family-3 rule: `L` and `B` must resolve before `O`'s default is evaluated.
|
|
559
|
+
*/
|
|
560
|
+
export type MapLoadingStateFn<L extends LoadingState, B, O extends LoadingState = LoadingStateWithValueType<L, B>> = (input: L, value?: B) => O;
|
|
561
|
+
/**
|
|
562
|
+
* Maps the value of an input {@link LoadingState} to the output value type.
|
|
563
|
+
*/
|
|
564
|
+
export type MapLoadingStateValuesFn<L extends LoadingState, B> = (input: LoadingStateValue<L>, state: L) => B;
|
|
565
|
+
/**
|
|
566
|
+
* Configuration for {@link mapLoadingStateResults}.
|
|
567
|
+
*
|
|
568
|
+
* The type parameter order is load-bearing: the input state `L` comes first so that it (and then `B`,
|
|
569
|
+
* inferred from `mapValue`'s return) is resolved before `O`'s default is evaluated. Any other order
|
|
570
|
+
* leaves `O` — and with it the input state's shape, including `page` — degraded.
|
|
459
571
|
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
*
|
|
572
|
+
* `O` is constrained to a bare {@link LoadingState} rather than to `LoadingState<B>`: a caller that
|
|
573
|
+
* threads its own output state type through (as the mapped-iteration layer does) cannot prove
|
|
574
|
+
* `M extends LoadingState<LoadingStateValue<M>>` while `M` is still generic. `mapState`'s signature
|
|
575
|
+
* still ties `O` back to `B`.
|
|
464
576
|
*/
|
|
465
|
-
export
|
|
466
|
-
export type MapLoadingStateFn<A, B, L extends LoadingState<A> = LoadingState<A>, O extends LoadingState<B> = LoadingState<B>> = (input: L, value?: B) => O;
|
|
467
|
-
export type MapLoadingStateValuesFn<A, B, L extends LoadingState<A> = LoadingState<A>> = (input: A, state: L) => B;
|
|
468
|
-
export interface MapLoadingStateResultsConfiguration<A, B, L extends LoadingState<A> = LoadingState<A>, O extends LoadingState<B> = LoadingState<B>> {
|
|
577
|
+
export interface MapLoadingStateResultsConfiguration<L extends LoadingState, B, O extends LoadingState = LoadingStateWithValueType<L, B>> {
|
|
469
578
|
readonly alwaysMapValue?: boolean;
|
|
470
|
-
readonly mapValue?: MapLoadingStateValuesFn<
|
|
471
|
-
readonly mapState?: MapLoadingStateFn<
|
|
579
|
+
readonly mapValue?: MapLoadingStateValuesFn<L, B>;
|
|
580
|
+
readonly mapState?: MapLoadingStateFn<L, B, O>;
|
|
472
581
|
}
|
|
473
582
|
/**
|
|
474
583
|
* Maps the value of a single {@link LoadingState} to a new type using the provided configuration.
|
|
@@ -476,6 +585,10 @@ export interface MapLoadingStateResultsConfiguration<A, B, L extends LoadingStat
|
|
|
476
585
|
* Preserves the loading/error metadata while transforming the value via `mapValue` or the entire
|
|
477
586
|
* state via `mapState`. When `alwaysMapValue` is true, maps even when the value is null/undefined.
|
|
478
587
|
*
|
|
588
|
+
* @param input - The loading state to transform.
|
|
589
|
+
* @param config - Mapping configuration.
|
|
590
|
+
* @returns The transformed loading state.
|
|
591
|
+
*
|
|
479
592
|
* @example
|
|
480
593
|
* ```ts
|
|
481
594
|
* const result = mapLoadingStateResults(successResult(0), {
|
|
@@ -483,16 +596,16 @@ export interface MapLoadingStateResultsConfiguration<A, B, L extends LoadingStat
|
|
|
483
596
|
* });
|
|
484
597
|
* // { value: 'Value: 0', loading: false }
|
|
485
598
|
* ```
|
|
486
|
-
*
|
|
487
|
-
* @param input - the loading state to transform
|
|
488
|
-
* @param config - mapping configuration
|
|
489
|
-
* @returns the transformed loading state
|
|
490
599
|
*/
|
|
491
|
-
export declare function mapLoadingStateResults<
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
export type
|
|
600
|
+
export declare function mapLoadingStateResults<L extends LoadingState, B, O extends LoadingState = LoadingStateWithValueType<L, B>>(input: L, config: MapLoadingStateResultsConfiguration<L, B, O>): O;
|
|
601
|
+
/**
|
|
602
|
+
* Extracts and maps the value out of a {@link LoadingState}, or returns undefined when it has none.
|
|
603
|
+
*/
|
|
604
|
+
export type MapLoadingStateValueFunction<L extends LoadingState, O> = MapFunction<L, Maybe<O>>;
|
|
605
|
+
/**
|
|
606
|
+
* Maps a {@link LoadingState}'s non-null value (and the state it came from) to the output type.
|
|
607
|
+
*/
|
|
608
|
+
export type MapLoadingStateValueMapFunction<L extends LoadingState, O> = (item: LoadingStateValue<L>, state: L) => Maybe<O>;
|
|
496
609
|
/**
|
|
497
610
|
* Creates a function that extracts and maps the value from a {@link LoadingState}, returning undefined
|
|
498
611
|
* when the state has no value.
|
|
@@ -502,4 +615,4 @@ export type MapLoadingStateValueMapFunction<O, I, L extends LoadingState<I> = Lo
|
|
|
502
615
|
*
|
|
503
616
|
* @__NO_SIDE_EFFECTS__
|
|
504
617
|
*/
|
|
505
|
-
export declare function mapLoadingStateValueFunction<
|
|
618
|
+
export declare function mapLoadingStateValueFunction<L extends LoadingState, O>(mapFn: MapLoadingStateValueMapFunction<L, O>): MapLoadingStateValueFunction<L, O>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type PageNumber } from '@dereekb/util';
|
|
2
2
|
import { type Observable, type OperatorFunction } from 'rxjs';
|
|
3
|
-
import { type
|
|
3
|
+
import { type ListLoadingState, type PageLoadingState } from './loading.state';
|
|
4
4
|
/**
|
|
5
5
|
* Whether the {@link ListLoadingState} has no value or an empty array.
|
|
6
6
|
*
|
|
@@ -16,7 +16,7 @@ import { type LoadingStateValue, type ListLoadingState, type PageLoadingState }
|
|
|
16
16
|
* isListLoadingStateWithEmptyValue(beginLoading()); // true (no value)
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
export declare function isListLoadingStateWithEmptyValue
|
|
19
|
+
export declare function isListLoadingStateWithEmptyValue(listLoadingState: ListLoadingState): boolean;
|
|
20
20
|
/**
|
|
21
21
|
* RxJS operator that maps each emitted {@link ListLoadingState} to a boolean indicating whether the list is empty.
|
|
22
22
|
*
|
|
@@ -66,4 +66,4 @@ export declare function pageLoadingStateFromObs<T>(obs: Observable<T>, firstOnly
|
|
|
66
66
|
* ).subscribe((items) => console.log(items)); // []
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
|
-
export declare function arrayValueFromFinishedLoadingState<
|
|
69
|
+
export declare function arrayValueFromFinishedLoadingState<T>(): OperatorFunction<ListLoadingState<T>, T[]>;
|