@dereekb/rxjs 11.1.8 → 12.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.cjs.js +1624 -1058
- package/index.esm.d.ts +1 -0
- package/index.esm.js +1722 -1540
- package/package.json +4 -3
- package/src/lib/filter/filter.source.d.ts +16 -4
- package/src/lib/loading/index.d.ts +1 -1
- package/src/lib/loading/loading.context.d.ts +18 -4
- package/src/lib/loading/loading.context.rxjs.d.ts +7 -0
- package/src/lib/loading/loading.context.simple.d.ts +2 -3
- package/src/lib/loading/loading.context.state.d.ts +79 -31
- package/src/lib/loading/loading.context.state.list.d.ts +35 -22
- package/src/lib/loading/loading.state.d.ts +24 -16
- package/src/lib/rxjs/getter.d.ts +8 -1
- package/src/lib/rxjs/value.d.ts +54 -5
- package/src/lib/subscription.d.ts +10 -10
- package/src/lib/loading/loading.context.state.value.d.ts +0 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/rxjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.1",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -21,5 +21,6 @@
|
|
|
21
21
|
"@dereekb/util": "*"
|
|
22
22
|
},
|
|
23
23
|
"module": "./index.esm.js",
|
|
24
|
-
"main": "./index.cjs.js"
|
|
25
|
-
|
|
24
|
+
"main": "./index.cjs.js",
|
|
25
|
+
"types": "./index.esm.d.ts"
|
|
26
|
+
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { type Observable } from 'rxjs';
|
|
2
2
|
import { type FilterSource } from './filter';
|
|
3
|
-
import { type
|
|
3
|
+
import { type MaybeObservableOrValue } from '../rxjs/getter';
|
|
4
4
|
import { type Destroyable, type Maybe } from '@dereekb/util';
|
|
5
|
+
export interface FilterSourceInstanceConfig<F> {
|
|
6
|
+
readonly initWithFilter?: Maybe<Observable<F>>;
|
|
7
|
+
readonly defaultFilter?: MaybeObservableOrValue<F>;
|
|
8
|
+
readonly filter?: Maybe<F>;
|
|
9
|
+
}
|
|
5
10
|
/**
|
|
6
11
|
* A basic FilterSource implementation.
|
|
7
12
|
*/
|
|
@@ -9,6 +14,9 @@ export declare class FilterSourceInstance<F> implements FilterSource<F>, Destroy
|
|
|
9
14
|
private readonly _initialFilterSub;
|
|
10
15
|
private readonly _initialFilterTakesPriority;
|
|
11
16
|
private readonly _filter;
|
|
17
|
+
/**
|
|
18
|
+
* The initial filter can only pass through observables that always emit a value.
|
|
19
|
+
*/
|
|
12
20
|
private readonly _initialFilter;
|
|
13
21
|
private readonly _defaultFilter;
|
|
14
22
|
readonly defaultFilter$: Observable<Maybe<F>>;
|
|
@@ -17,15 +25,19 @@ export declare class FilterSourceInstance<F> implements FilterSource<F>, Destroy
|
|
|
17
25
|
* filter$ uses the latest value from any filter.
|
|
18
26
|
*/
|
|
19
27
|
readonly filter$: Observable<F>;
|
|
28
|
+
constructor(config?: FilterSourceInstanceConfig<F>);
|
|
20
29
|
initWithFilter(filterObs: Observable<F>): void;
|
|
21
|
-
setDefaultFilter(filter:
|
|
30
|
+
setDefaultFilter(filter: MaybeObservableOrValue<F>): void;
|
|
22
31
|
setFilter(filter: F): void;
|
|
23
32
|
/**
|
|
24
33
|
* Resets the current filter to be the default filter.
|
|
25
34
|
*/
|
|
26
35
|
resetFilter(): void;
|
|
27
|
-
|
|
28
|
-
set initialFilterTakesPriority(initialFilterTakesPriority: boolean);
|
|
36
|
+
setInitialFilterTakesPriority(initialFilterTakesPriority: boolean): void;
|
|
29
37
|
protected initFilterTakesPriority(): void;
|
|
30
38
|
destroy(): void;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated use setInitialFilterTakesPriority instead.
|
|
41
|
+
*/
|
|
42
|
+
set initialFilterTakesPriority(initialFilterTakesPriority: boolean);
|
|
31
43
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
export * from './loading.context.rxjs';
|
|
1
2
|
export * from './loading.context.state';
|
|
2
3
|
export * from './loading.context.state.list';
|
|
3
|
-
export * from './loading.context.state.value';
|
|
4
4
|
export * from './loading.context.simple';
|
|
5
5
|
export * from './loading.context';
|
|
6
6
|
export * from './loading.context.value';
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import { type Observable } from 'rxjs';
|
|
2
|
-
import { type LoadingErrorPair } from './loading.state';
|
|
2
|
+
import { type LoadingState, type LoadingErrorPair } from './loading.state';
|
|
3
|
+
/**
|
|
4
|
+
* A LoadingErrorPair that always defines a loading value.
|
|
5
|
+
*/
|
|
3
6
|
export interface LoadingContextEvent extends LoadingErrorPair {
|
|
4
|
-
loading: boolean;
|
|
7
|
+
readonly loading: boolean;
|
|
5
8
|
}
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
/**
|
|
10
|
+
* An observable LoadingContext that provides a stream of LoadingContextEvents.
|
|
11
|
+
*/
|
|
12
|
+
export interface LoadingContext<E extends LoadingContextEvent = LoadingContextEvent> {
|
|
13
|
+
/**
|
|
14
|
+
* Stream of events that provide the current LoadingContextEvent for the LoadingContext.
|
|
15
|
+
*/
|
|
16
|
+
readonly stream$: Observable<E>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A LoadingContextEvent that has a value.
|
|
20
|
+
*/
|
|
21
|
+
export interface LoadingStateContextEvent<T = unknown> extends LoadingContextEvent, Omit<LoadingState<T>, 'loading'> {
|
|
8
22
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type OperatorFunction } from 'rxjs';
|
|
2
|
+
import { type LoadingContext, type LoadingContextEvent } from './loading.context';
|
|
3
|
+
import { type Maybe } from '@dereekb/util';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a switchMap operator that will emit the stream of events from the input LoadingContext as soon as a non-null LoadingContext is emitted.
|
|
6
|
+
*/
|
|
7
|
+
export declare function switchMapMaybeLoadingContextStream(): OperatorFunction<Maybe<LoadingContext>, Maybe<LoadingContextEvent>>;
|
|
@@ -5,13 +5,12 @@ import { type LoadingContext, type LoadingContextEvent } from './loading.context
|
|
|
5
5
|
* Simple LoadingContext implementation
|
|
6
6
|
*/
|
|
7
7
|
export declare class SimpleLoadingContext implements LoadingContext, Destroyable {
|
|
8
|
-
private _subject;
|
|
9
|
-
|
|
8
|
+
private readonly _subject;
|
|
9
|
+
readonly stream$: Observable<LoadingContextEvent>;
|
|
10
10
|
constructor(loading?: boolean);
|
|
11
11
|
destroy(): void;
|
|
12
12
|
hasError(): boolean;
|
|
13
13
|
clearError(): void;
|
|
14
|
-
get stream$(): Observable<LoadingContextEvent>;
|
|
15
14
|
setSuccess(): void;
|
|
16
15
|
setLoading(loading?: boolean): void;
|
|
17
16
|
setError(error: ReadableError, loading?: boolean): void;
|
|
@@ -1,46 +1,94 @@
|
|
|
1
1
|
import { type Maybe, type Destroyable } from '@dereekb/util';
|
|
2
2
|
import { type Observable } from 'rxjs';
|
|
3
|
-
import { type LoadingContext, type LoadingContextEvent } from './loading.context';
|
|
3
|
+
import { type LoadingStateContextEvent, type LoadingContext, type LoadingContextEvent } from './loading.context';
|
|
4
4
|
import { type LoadingState } from './loading.state';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export interface
|
|
5
|
+
/**
|
|
6
|
+
* A LoadingContext that provides several accessors to a LoadingState<T> and corresponding LoadingContextEvent
|
|
7
|
+
*/
|
|
8
|
+
export interface LoadingStateContext<T = unknown, S extends LoadingState<T> = LoadingState<T>, E extends LoadingContextEvent = LoadingContextEvent & S> extends LoadingContext<E> {
|
|
9
9
|
/**
|
|
10
|
-
* The
|
|
10
|
+
* The current observable stream of the state observable.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
readonly currentStateStream$: Observable<Maybe<Observable<Maybe<S>>>>;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* The latest non-null observable stream of the state observable.
|
|
15
|
+
*/
|
|
16
|
+
readonly stateStream$: Observable<Observable<Maybe<S>>>;
|
|
17
|
+
/**
|
|
18
|
+
* Current state.
|
|
19
|
+
*/
|
|
20
|
+
readonly currentState$: Observable<Maybe<S>>;
|
|
21
|
+
/**
|
|
22
|
+
* Latest non-null state.
|
|
15
23
|
*/
|
|
16
|
-
showLoadingOnNoValue?: boolean;
|
|
17
|
-
}
|
|
18
|
-
export interface AbstractLoadingStateContext<T = unknown, S extends LoadingState<T> = LoadingState<T>, E extends LoadingContextEvent = LoadingContextEvent> {
|
|
19
|
-
readonly stateObs$: Observable<Maybe<Observable<S>>>;
|
|
20
|
-
readonly stateSubject$: Observable<Observable<S>>;
|
|
21
24
|
readonly state$: Observable<S>;
|
|
22
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Observable for the current loading state from the event stream.
|
|
27
|
+
*/
|
|
23
28
|
readonly loading$: Observable<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* The current value. Always provided, even while loading.
|
|
31
|
+
*/
|
|
32
|
+
readonly currentValue$: Observable<Maybe<T>>;
|
|
33
|
+
/**
|
|
34
|
+
* The latest value from the most recent loaded state.
|
|
35
|
+
*/
|
|
36
|
+
readonly valueAfterLoaded$: Observable<Maybe<T>>;
|
|
37
|
+
/**
|
|
38
|
+
* The latest non-null value from valueAfterLoaded$.
|
|
39
|
+
*/
|
|
40
|
+
readonly value$: Observable<T>;
|
|
24
41
|
}
|
|
25
|
-
export type LoadingStateContextInstanceInputConfig<S, C> = Observable<S> | C;
|
|
26
42
|
/**
|
|
27
|
-
*
|
|
43
|
+
* A LoadingStateContext that can be updated and destroyed.
|
|
28
44
|
*/
|
|
29
|
-
export
|
|
30
|
-
private _stateSubject;
|
|
31
|
-
private _config;
|
|
32
|
-
readonly config$: Observable<C>;
|
|
33
|
-
readonly stateSubject$: Observable<Observable<S>>;
|
|
34
|
-
readonly state$: Observable<S>;
|
|
35
|
-
readonly stateObs$: Observable<Maybe<Observable<S>>>;
|
|
36
|
-
readonly stream$: Observable<E>;
|
|
45
|
+
export interface MutableLoadingStateContext<T = unknown, S extends LoadingState<T> = LoadingState<T>, E extends LoadingStateContextEvent = LoadingContextEvent & S> extends LoadingStateContext<T, S, E>, Destroyable {
|
|
37
46
|
/**
|
|
38
|
-
*
|
|
47
|
+
* Sets a new state observable.
|
|
48
|
+
*
|
|
49
|
+
* @param obs Observable
|
|
39
50
|
*/
|
|
40
|
-
|
|
41
|
-
readonly loading$: Observable<boolean>;
|
|
42
|
-
constructor(config?: LoadingStateContextInstanceInputConfig<S, C>);
|
|
43
|
-
protected abstract loadingEventForLoadingPair(state: S, config: C): E;
|
|
44
|
-
setStateObs(state: Maybe<Observable<S>>): void;
|
|
45
|
-
destroy(): void;
|
|
51
|
+
setStateObs(obs: Maybe<Observable<Maybe<S>>>): void;
|
|
46
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Configuration for loadingStateContext().
|
|
55
|
+
*/
|
|
56
|
+
export interface LoadingStateContextConfig<T = unknown, S extends LoadingState<T> = LoadingState<T>, E extends LoadingStateContextEvent = LoadingContextEvent & S> {
|
|
57
|
+
/**
|
|
58
|
+
* The initial observable.
|
|
59
|
+
*/
|
|
60
|
+
readonly obs?: Maybe<Observable<Maybe<S>>>;
|
|
61
|
+
/**
|
|
62
|
+
* Whether or not to show loading if finished loading and the value is undefined.
|
|
63
|
+
*
|
|
64
|
+
* Defaults to false.
|
|
65
|
+
*/
|
|
66
|
+
readonly showLoadingOnUndefinedValue?: Maybe<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* Optional function to generate a LoadingContextEvent from a LoadingState and this config.
|
|
69
|
+
*
|
|
70
|
+
* @param state the current state
|
|
71
|
+
* @param config this config
|
|
72
|
+
* @returns the event to emit
|
|
73
|
+
*/
|
|
74
|
+
readonly loadingEventForLoadingPair?: Maybe<(state: S, config: LoadingEventForLoadingPairConfigInput) => E>;
|
|
75
|
+
/**
|
|
76
|
+
* Alias for showLoadingOnUndefinedValue.
|
|
77
|
+
*
|
|
78
|
+
* @deprecated Use showLoadingOnUndefinedValue instead.
|
|
79
|
+
*/
|
|
80
|
+
readonly showLoadingOnNoValue?: Maybe<boolean>;
|
|
81
|
+
}
|
|
82
|
+
export type LoadingEventForLoadingPairConfigInput = Pick<LoadingStateContextConfig, 'showLoadingOnUndefinedValue'>;
|
|
83
|
+
export declare const DEFAULT_LOADING_EVENT_FOR_LOADING_PAIR_FUNCTION: <T = unknown, S extends LoadingState<T> = LoadingState<T>, E extends LoadingStateContextEvent = LoadingContextEvent & S>(state: S, input: LoadingEventForLoadingPairConfigInput) => LoadingStateContextEvent<T>;
|
|
84
|
+
/**
|
|
85
|
+
* Input for loadingStateContext()
|
|
86
|
+
*/
|
|
87
|
+
export type LoadingStateContextInput<T = unknown, S extends LoadingState<T> = LoadingState<T>, E extends LoadingStateContextEvent = LoadingContextEvent & S> = LoadingStateContextConfig<T, S, E> | LoadingStateContextConfig<T, S, E>['obs'];
|
|
88
|
+
/**
|
|
89
|
+
* Creates a new LoadingStateContext from the input.
|
|
90
|
+
|
|
91
|
+
* @param input LoadingStateContextInput
|
|
92
|
+
* @returns LoadingStateContext
|
|
93
|
+
*/
|
|
94
|
+
export declare function loadingStateContext<T = unknown, S extends LoadingState<T> = LoadingState<T>, E extends LoadingStateContextEvent = LoadingContextEvent & S>(input?: LoadingStateContextInput<T, S, E>): MutableLoadingStateContext<T, S, E>;
|
|
@@ -1,36 +1,32 @@
|
|
|
1
1
|
import { type LimitArrayConfig, type Maybe } from '@dereekb/util';
|
|
2
2
|
import { type Observable } from 'rxjs';
|
|
3
3
|
import { type ListLoadingState } from './loading.state';
|
|
4
|
-
import { type
|
|
5
|
-
export interface
|
|
6
|
-
value?: Maybe<T[]>;
|
|
7
|
-
}
|
|
8
|
-
export interface LoadingEventForListLoadingStateConfig<S extends ListLoadingState<unknown> = ListLoadingState<unknown>> extends AbstractLoadingEventForLoadingPairConfig<S>, Partial<LimitArrayConfig> {
|
|
9
|
-
}
|
|
10
|
-
export interface ListLoadingStateContext<L = unknown, S extends ListLoadingState<L> = ListLoadingState<L>> extends AbstractLoadingStateContext<L[], S, ListLoadingStateContextEvent<L>> {
|
|
11
|
-
readonly list$: Observable<L[]>;
|
|
12
|
-
readonly isEmpty$: Observable<boolean>;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* LoadingContext implementation that uses a ListLoadingState observable.
|
|
16
|
-
*/
|
|
17
|
-
export declare class ListLoadingStateContextInstance<L = unknown, S extends ListLoadingState<L> = ListLoadingState<L>> extends AbstractLoadingStateContextInstance<L[], S, ListLoadingStateContextEvent<L>, LoadingEventForListLoadingStateConfig<S>> {
|
|
4
|
+
import { type LoadingStateContext, type LoadingStateContextConfig, type LoadingStateContextInput, type MutableLoadingStateContext } from './loading.context.state';
|
|
5
|
+
export interface ListLoadingStateContext<L = unknown, S extends ListLoadingState<L> = ListLoadingState<L>> extends Omit<LoadingStateContext<L[], S>, 'value$' | 'currentValue$' | 'valueAfterLoaded$'> {
|
|
18
6
|
/**
|
|
19
|
-
*
|
|
7
|
+
* The current list. Always provided, even while loading.
|
|
20
8
|
*/
|
|
21
|
-
readonly
|
|
9
|
+
readonly currentList$: Observable<Maybe<L[]>>;
|
|
22
10
|
/**
|
|
23
|
-
*
|
|
11
|
+
* The latest list from the most recent loaded state.
|
|
24
12
|
*/
|
|
25
|
-
readonly
|
|
13
|
+
readonly listAfterLoaded$: Observable<Maybe<L[]>>;
|
|
14
|
+
/**
|
|
15
|
+
* The latest list from listAfterLoaded$, or a default value if the list was empty.
|
|
16
|
+
*/
|
|
17
|
+
readonly list$: Observable<L[]>;
|
|
26
18
|
/**
|
|
27
|
-
* Whether or not the
|
|
19
|
+
* Whether or not the currentList$ value is empty.
|
|
28
20
|
*
|
|
29
|
-
* Only resolves
|
|
21
|
+
* Only resolves after the first non-loading event has occured.
|
|
30
22
|
*
|
|
31
23
|
* After that, will return true if the value is empty even if loading a new value.
|
|
32
24
|
*/
|
|
33
25
|
readonly isEmpty$: Observable<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Returns true while loading and the current value is considered empty.
|
|
28
|
+
*/
|
|
29
|
+
readonly isEmptyLoading$: Observable<boolean>;
|
|
34
30
|
/**
|
|
35
31
|
* Whether or not the current value is empty and not loading.
|
|
36
32
|
*
|
|
@@ -39,6 +35,23 @@ export declare class ListLoadingStateContextInstance<L = unknown, S extends List
|
|
|
39
35
|
* After that, will return true if the value is empty even if loading a new value.
|
|
40
36
|
*/
|
|
41
37
|
readonly isEmptyAndNotLoading$: Observable<boolean>;
|
|
42
|
-
protected loadingEventForLoadingPair(state: S, config?: LoadingEventForListLoadingStateConfig): ListLoadingStateContextEvent<L>;
|
|
43
38
|
}
|
|
44
|
-
|
|
39
|
+
/**
|
|
40
|
+
* A ListLoadingStateContext that can be updated and destroyed.
|
|
41
|
+
*/
|
|
42
|
+
export type MutableListLoadingStateContext<L = unknown, S extends ListLoadingState<L> = ListLoadingState<L>> = ListLoadingStateContext<L, S> & Pick<MutableLoadingStateContext<L[], S>, 'setStateObs' | 'destroy'>;
|
|
43
|
+
/**
|
|
44
|
+
* Configuration for listLoadingStateContext().
|
|
45
|
+
*/
|
|
46
|
+
export type ListLoadingStateContextConfig<L, S extends ListLoadingState<L> = ListLoadingState<L>> = Omit<LoadingStateContextConfig<L[], S>, 'loadingEventForLoadingPair'> & Partial<LimitArrayConfig>;
|
|
47
|
+
/**
|
|
48
|
+
* Input for listLoadingStateContext().
|
|
49
|
+
*/
|
|
50
|
+
export type ListLoadingStateContextInput<L, S extends ListLoadingState<L> = ListLoadingState<L>> = Omit<LoadingStateContextInput<L[], S>, 'loadingEventForLoadingPair'> | ListLoadingStateContextConfig<L, S>;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a ListLoadingStateContext.
|
|
53
|
+
*
|
|
54
|
+
* @param input Optional configuration for the ListLoadingStateContext.
|
|
55
|
+
* @returns A ListLoadingStateContext.
|
|
56
|
+
*/
|
|
57
|
+
export declare function listLoadingStateContext<L, S extends ListLoadingState<L> = ListLoadingState<L>>(input?: ListLoadingStateContextInput<L, S>): MutableListLoadingStateContext<L, S>;
|
|
@@ -8,17 +8,25 @@ export interface LoadingErrorPair {
|
|
|
8
8
|
*
|
|
9
9
|
* Not being specified is considered not being loaded.
|
|
10
10
|
*/
|
|
11
|
-
loading?: Maybe<boolean>;
|
|
11
|
+
readonly loading?: Maybe<boolean>;
|
|
12
12
|
/**
|
|
13
13
|
* A Readable server error.
|
|
14
14
|
*/
|
|
15
|
-
error?: Maybe<ReadableError>;
|
|
15
|
+
readonly error?: Maybe<ReadableError>;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns true if the input LoadingErrorPair has the same loading (truthy vs falsy) and error values as the other LoadingErrorPair.
|
|
19
|
+
*
|
|
20
|
+
* @param a LoadingErrorPair a
|
|
21
|
+
* @param b LoadingErrorPair b
|
|
22
|
+
* @returns Returns true if the input's metadata is considered equivalent.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isLoadingStateMetadataEqual(a: Partial<LoadingErrorPair>, b: Partial<LoadingErrorPair>): boolean;
|
|
17
25
|
/**
|
|
18
26
|
* A value/error pair used in loading situations.
|
|
19
27
|
*/
|
|
20
28
|
export interface LoadingState<T = unknown> extends LoadingErrorPair {
|
|
21
|
-
value?: Maybe<T>;
|
|
29
|
+
readonly value?: Maybe<T>;
|
|
22
30
|
}
|
|
23
31
|
/**
|
|
24
32
|
* Returns the value type inferred from the LoadingState type.
|
|
@@ -32,19 +40,19 @@ export type LoadingStateWithValueType<L extends LoadingState, T> = L extends Loa
|
|
|
32
40
|
* Loading state with a value key.
|
|
33
41
|
*/
|
|
34
42
|
export type LoadingStateWithValue<T = unknown> = LoadingState<T> & {
|
|
35
|
-
value: Maybe<T>;
|
|
43
|
+
readonly value: Maybe<T>;
|
|
36
44
|
};
|
|
37
45
|
/**
|
|
38
46
|
* Loading state with a value key and a non-maybe value.
|
|
39
47
|
*/
|
|
40
48
|
export type LoadingStateWithDefinedValue<T = unknown> = LoadingState<T> & {
|
|
41
|
-
value: T;
|
|
49
|
+
readonly value: T;
|
|
42
50
|
};
|
|
43
51
|
/**
|
|
44
52
|
* Loading state with an error
|
|
45
53
|
*/
|
|
46
54
|
export type LoadingStateWithError<T = unknown> = LoadingState<T> & {
|
|
47
|
-
error: ReadableError;
|
|
55
|
+
readonly error: ReadableError;
|
|
48
56
|
};
|
|
49
57
|
/**
|
|
50
58
|
* Convenience identifier for a LoadingState that returns a list.
|
|
@@ -123,39 +131,39 @@ export declare function isAnyLoadingStateInLoadingState(states: LoadingState[]):
|
|
|
123
131
|
* @returns
|
|
124
132
|
*/
|
|
125
133
|
export declare function areAllLoadingStatesFinishedLoading(states: LoadingState[]): boolean;
|
|
126
|
-
export declare function isLoadingStateWithStateType(type: LoadingStateType): <L extends LoadingState
|
|
134
|
+
export declare function isLoadingStateWithStateType(type: LoadingStateType): <L extends LoadingState>(state: Maybe<L>) => boolean;
|
|
127
135
|
/**
|
|
128
136
|
* Returns true if the input LoadingState passed to loadingStateType() returns IDLE.
|
|
129
137
|
*
|
|
130
138
|
* @param state
|
|
131
139
|
* @returns
|
|
132
140
|
*/
|
|
133
|
-
export declare const isLoadingStateInIdleState: <L extends LoadingState
|
|
141
|
+
export declare const isLoadingStateInIdleState: <L extends LoadingState>(state: Maybe<L>) => boolean;
|
|
134
142
|
/**
|
|
135
143
|
* Returns true if the input LoadingState passed to loadingStateType() returns LOADING.
|
|
136
144
|
*
|
|
137
145
|
* @param state
|
|
138
146
|
* @returns
|
|
139
147
|
*/
|
|
140
|
-
export declare const isLoadingStateLoading: <L extends LoadingState
|
|
148
|
+
export declare const isLoadingStateLoading: <L extends LoadingState>(state: Maybe<L>) => boolean;
|
|
141
149
|
/**
|
|
142
150
|
* Alias of isLoadingStateLoading.
|
|
143
151
|
*/
|
|
144
|
-
export declare const isLoadingStateInLoadingState: <L extends LoadingState
|
|
152
|
+
export declare const isLoadingStateInLoadingState: <L extends LoadingState>(state: Maybe<L>) => boolean;
|
|
145
153
|
/**
|
|
146
154
|
* Returns true if the input LoadingState passed to loadingStateType() returns SUCCESS.
|
|
147
155
|
*
|
|
148
156
|
* @param state
|
|
149
157
|
* @returns
|
|
150
158
|
*/
|
|
151
|
-
export declare const isLoadingStateInSuccessState: <L extends LoadingState
|
|
159
|
+
export declare const isLoadingStateInSuccessState: <L extends LoadingState>(state: Maybe<L>) => boolean;
|
|
152
160
|
/**
|
|
153
161
|
* Returns true if the input LoadingState passed to loadingStateType() returns ERROR.
|
|
154
162
|
*
|
|
155
163
|
* @param state
|
|
156
164
|
* @returns
|
|
157
165
|
*/
|
|
158
|
-
export declare const isLoadingStateInErrorState: <L extends LoadingState
|
|
166
|
+
export declare const isLoadingStateInErrorState: <L extends LoadingState>(state: Maybe<L>) => boolean;
|
|
159
167
|
/**
|
|
160
168
|
* Whether or not the input LoadingState has a non-undefined value.
|
|
161
169
|
*
|
|
@@ -251,19 +259,19 @@ export declare const allLoadingStatesHaveFinishedLoading: typeof areAllLoadingSt
|
|
|
251
259
|
/**
|
|
252
260
|
* @deprecated use isLoadingStateInIdleState instead.
|
|
253
261
|
*/
|
|
254
|
-
export declare const loadingStateIsIdle: <L extends LoadingState
|
|
262
|
+
export declare const loadingStateIsIdle: <L extends LoadingState>(state: Maybe<L>) => boolean;
|
|
255
263
|
/**
|
|
256
264
|
* @deprecated use isLoadingStateInSuccessState instead.
|
|
257
265
|
*/
|
|
258
|
-
export declare const isSuccessLoadingState: <L extends LoadingState
|
|
266
|
+
export declare const isSuccessLoadingState: <L extends LoadingState>(state: Maybe<L>) => boolean;
|
|
259
267
|
/**
|
|
260
268
|
* @deprecated use isLoadingStateInErrorState instead.
|
|
261
269
|
*/
|
|
262
|
-
export declare const isErrorLoadingState: <L extends LoadingState
|
|
270
|
+
export declare const isErrorLoadingState: <L extends LoadingState>(state: Maybe<L>) => boolean;
|
|
263
271
|
/**
|
|
264
272
|
* @deprecated Use isLoadingStateLoading instead.
|
|
265
273
|
*/
|
|
266
|
-
export declare const loadingStateIsLoading: <L extends LoadingState
|
|
274
|
+
export declare const loadingStateIsLoading: <L extends LoadingState>(state: Maybe<L>) => boolean;
|
|
267
275
|
/**
|
|
268
276
|
* @deprecated use isLoadingStateFinishedLoading instead.
|
|
269
277
|
*/
|
package/src/lib/rxjs/getter.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { type Observable, type OperatorFunction, type Subscription, type Observe
|
|
|
4
4
|
* A value that is either the value or an observable that returns the value.
|
|
5
5
|
*/
|
|
6
6
|
export type ObservableOrValue<T> = T | Observable<T>;
|
|
7
|
+
export type MaybeObservableOrValue<T> = Maybe<ObservableOrValue<Maybe<T>>>;
|
|
7
8
|
/**
|
|
8
9
|
* Wraps the input value as an observable, if it is not an observable.
|
|
9
10
|
*/
|
|
@@ -12,9 +13,15 @@ export declare function asObservable<T>(valueOrObs: Maybe<ObservableOrValue<T>>)
|
|
|
12
13
|
/**
|
|
13
14
|
* Switch map for an ObservableGetter that pipes through the value.
|
|
14
15
|
*
|
|
15
|
-
* @returns
|
|
16
|
+
* @returns OperatorFunction<ObservableOrValue<T>, T>
|
|
16
17
|
*/
|
|
17
18
|
export declare function valueFromObservableOrValue<T>(): OperatorFunction<ObservableOrValue<T>, T>;
|
|
19
|
+
/**
|
|
20
|
+
* Switch map for an ObservableGetter that pipes through the Maybe value.
|
|
21
|
+
*
|
|
22
|
+
* @returns OperatorFunction<Maybe<ObservableOrValue<T>>, Maybe<T>>
|
|
23
|
+
*/
|
|
24
|
+
export declare function maybeValueFromObservableOrValue<T>(): OperatorFunction<MaybeObservableOrValue<T>, Maybe<T>>;
|
|
18
25
|
/**
|
|
19
26
|
* A GetterOrValue of a ObservableOrValue.
|
|
20
27
|
*/
|
package/src/lib/rxjs/value.d.ts
CHANGED
|
@@ -1,16 +1,55 @@
|
|
|
1
1
|
import { type MonoTypeOperatorFunction, type Observable, type OperatorFunction } from 'rxjs';
|
|
2
2
|
import { type DecisionFunction, type GetterOrValue, type MapFunction, type Maybe } from '@dereekb/util';
|
|
3
|
-
import { type MaybeObservableOrValueGetter, type ObservableOrValueGetter } from './getter';
|
|
3
|
+
import { type MaybeObservableOrValueGetter, type ObservableOrValueGetter, type MaybeObservableOrValue } from './getter';
|
|
4
4
|
import { type ObservableDecisionFunction } from './decision';
|
|
5
|
+
/**
|
|
6
|
+
* Function that checks the input value and returns an observable that emits a boolean.
|
|
7
|
+
*/
|
|
5
8
|
export type IsCheckFunction<T = unknown> = (value: T) => Observable<boolean>;
|
|
6
9
|
/**
|
|
7
|
-
* Function that validates the input value and returns an observable.
|
|
10
|
+
* Function that validates the input value and returns an observable that emits true if the value is valid.
|
|
8
11
|
*/
|
|
9
12
|
export type IsValidFunction<T = unknown> = IsCheckFunction<T>;
|
|
10
13
|
/**
|
|
11
|
-
* Function that checks
|
|
14
|
+
* Function that checks equality of the input value and returns an observable that emits true if the value is equal.
|
|
15
|
+
*/
|
|
16
|
+
export type IsEqualFunction<T = unknown> = IsCheckFunction<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Function that checks modification status of the input value and returns an observable that emits true if the value is modified.
|
|
12
19
|
*/
|
|
13
20
|
export type IsModifiedFunction<T = unknown> = IsCheckFunction<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Creates an IsModifiedFunction from an IsEqualFunction, or from IsModifiedFunctionInput.
|
|
23
|
+
*
|
|
24
|
+
* @param isEqualFunction
|
|
25
|
+
*/
|
|
26
|
+
export declare function makeIsModifiedFunction<T>(isEqualFunction: IsEqualFunction<T>): IsModifiedFunction<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Configuration for creating an Observable<IsModifiedFunction>.
|
|
29
|
+
*/
|
|
30
|
+
export interface MakeIsModifiedFunctionObservableConfig<T = unknown> {
|
|
31
|
+
/**
|
|
32
|
+
* Observable or value of the IsModifiedFunction to use, if applicable.
|
|
33
|
+
*/
|
|
34
|
+
readonly isModified?: MaybeObservableOrValue<IsModifiedFunction<T>>;
|
|
35
|
+
/**
|
|
36
|
+
* Observable or value of the IsEqualFunction to use, if applicable.
|
|
37
|
+
*/
|
|
38
|
+
readonly isEqual?: MaybeObservableOrValue<IsEqualFunction<T>>;
|
|
39
|
+
/**
|
|
40
|
+
* The default function to use if no other function is provided.
|
|
41
|
+
*
|
|
42
|
+
* Defaults to a function that returns true.
|
|
43
|
+
*/
|
|
44
|
+
readonly defaultFunction?: Maybe<IsModifiedFunction<T>>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates an Observable<IsModifiedFunction> from the input config.
|
|
48
|
+
*
|
|
49
|
+
* @param config MakeIsModifiedFunctionObservableConfig.
|
|
50
|
+
* @returns Observable<IsModifiedFunction<T>>
|
|
51
|
+
*/
|
|
52
|
+
export declare function makeIsModifiedFunctionObservable<T>(config: MakeIsModifiedFunctionObservableConfig<T>): Observable<IsModifiedFunction<T>>;
|
|
14
53
|
export declare function makeReturnIfIsFunction<T>(isCheckFunction: Maybe<IsModifiedFunction<T>>, defaultValueOnMaybe?: boolean): (value: Maybe<T>) => Observable<Maybe<T>>;
|
|
15
54
|
export declare function returnIfIs<T>(isCheckFunction: Maybe<IsModifiedFunction<T>>, value: Maybe<T>, defaultValueOnMaybe?: boolean): Observable<Maybe<T>>;
|
|
16
55
|
export declare function makeCheckIsFunction<T>(isCheckFunction: Maybe<IsModifiedFunction<T>>, defaultValueOnMaybe?: boolean): (value: Maybe<T>) => Observable<boolean>;
|
|
@@ -60,7 +99,9 @@ export declare function switchMapObject<T extends object>(config: SwitchMapObjec
|
|
|
60
99
|
* @param defaultValue
|
|
61
100
|
* @returns
|
|
62
101
|
*/
|
|
102
|
+
export declare function switchMapWhileTrue<T = unknown>(obs: ObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
|
|
63
103
|
export declare function switchMapWhileTrue<T = unknown>(obs: MaybeObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
|
|
104
|
+
export declare function switchMapWhileTrue<T = unknown>(obs: ObservableOrValueGetter<T>, otherwise: ObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
|
|
64
105
|
export declare function switchMapWhileTrue<T = unknown>(obs: MaybeObservableOrValueGetter<T>, otherwise?: MaybeObservableOrValueGetter<T>): OperatorFunction<boolean, Maybe<T>>;
|
|
65
106
|
/**
|
|
66
107
|
* Provides a switchMap that will emit from the input observable if the value is false, otherwise emits the otherwise value or empty.
|
|
@@ -68,7 +109,9 @@ export declare function switchMapWhileTrue<T = unknown>(obs: MaybeObservableOrVa
|
|
|
68
109
|
* @param defaultValue
|
|
69
110
|
* @returns
|
|
70
111
|
*/
|
|
112
|
+
export declare function switchMapWhileFalse<T = unknown>(obs: ObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
|
|
71
113
|
export declare function switchMapWhileFalse<T = unknown>(obs: MaybeObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
|
|
114
|
+
export declare function switchMapWhileFalse<T = unknown>(obs: ObservableOrValueGetter<T>, otherwise: ObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
|
|
72
115
|
export declare function switchMapWhileFalse<T = unknown>(obs: MaybeObservableOrValueGetter<T>, otherwise?: MaybeObservableOrValueGetter<T>): OperatorFunction<boolean, Maybe<T>>;
|
|
73
116
|
/**
|
|
74
117
|
* Provides a switchMap that will emit from the input observable if the value matches the switchOnValue, otherwise emits the otherwise value or empty.
|
|
@@ -79,11 +122,17 @@ export declare function switchMapWhileFalse<T = unknown>(obs: MaybeObservableOrV
|
|
|
79
122
|
export declare function switchMapOnBoolean<T = unknown>(switchOnValue: boolean, obs: MaybeObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
|
|
80
123
|
export declare function switchMapOnBoolean<T = unknown>(switchOnValue: boolean, obs: MaybeObservableOrValueGetter<T>, otherwise?: MaybeObservableOrValueGetter<T>): OperatorFunction<boolean, Maybe<T>>;
|
|
81
124
|
/**
|
|
82
|
-
* Combines both filterMaybe and switchMap to build a subscriber that emits only concrete
|
|
125
|
+
* Combines both filterMaybe and switchMap to build a subscriber that emits values only from a concrete Observable, filtering out null/undefined Observables.
|
|
126
|
+
*
|
|
127
|
+
* @returns
|
|
128
|
+
*/
|
|
129
|
+
export declare function switchMapFilterMaybe<T = unknown>(): OperatorFunction<Maybe<Observable<Maybe<T>>>, T>;
|
|
130
|
+
/**
|
|
131
|
+
* Converts a Maybe<Observable<Maybe<T>>> to an Observable<Maybe<T>> that emits null/undefined if the input observable is also null/undefined.
|
|
83
132
|
*
|
|
84
133
|
* @returns
|
|
85
134
|
*/
|
|
86
|
-
export declare function
|
|
135
|
+
export declare function switchMapMaybe<T = unknown>(): OperatorFunction<Maybe<Observable<Maybe<T>>>, Maybe<T>>;
|
|
87
136
|
/**
|
|
88
137
|
* Performs the input map function on the input if it is not null/undefined.
|
|
89
138
|
*
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Unsubscribable } from 'rxjs';
|
|
2
2
|
import { type ArrayOrValue, type Destroyable, type Maybe } from '@dereekb/util';
|
|
3
3
|
/**
|
|
4
|
-
* Destroyable object that wraps
|
|
4
|
+
* Destroyable object that wraps an Unsubscribable.
|
|
5
5
|
*/
|
|
6
|
-
export declare class SubscriptionObject implements Destroyable {
|
|
6
|
+
export declare class SubscriptionObject<T extends Unsubscribable = Unsubscribable> implements Destroyable {
|
|
7
7
|
private _subscription?;
|
|
8
|
-
constructor(sub?: Maybe<
|
|
8
|
+
constructor(sub?: Maybe<T>);
|
|
9
9
|
get hasSubscription(): boolean;
|
|
10
|
-
set subscription(sub: Maybe<
|
|
11
|
-
setSub(sub: Maybe<
|
|
10
|
+
set subscription(sub: Maybe<T | void>);
|
|
11
|
+
setSub(sub: Maybe<T | void>): void;
|
|
12
12
|
unsub(): void;
|
|
13
13
|
destroy(): void;
|
|
14
14
|
}
|
|
@@ -17,12 +17,12 @@ export declare class SubscriptionObject implements Destroyable {
|
|
|
17
17
|
*
|
|
18
18
|
* NOTE: In some cases it might be better to use RXJS's merge(...[]) and subscribe to a single item.
|
|
19
19
|
*/
|
|
20
|
-
export declare class MultiSubscriptionObject implements Destroyable {
|
|
20
|
+
export declare class MultiSubscriptionObject<T extends Unsubscribable = Unsubscribable> implements Destroyable {
|
|
21
21
|
private _subscriptions?;
|
|
22
|
-
constructor(subs?: ArrayOrValue<
|
|
22
|
+
constructor(subs?: ArrayOrValue<T>);
|
|
23
23
|
get hasSubscription(): boolean;
|
|
24
|
-
set subscriptions(subs: ArrayOrValue<
|
|
25
|
-
setSubs(subs: ArrayOrValue<
|
|
24
|
+
set subscriptions(subs: ArrayOrValue<T>);
|
|
25
|
+
setSubs(subs: ArrayOrValue<T>): void;
|
|
26
26
|
unsub(): void;
|
|
27
27
|
destroy(): void;
|
|
28
28
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type Maybe } from '@dereekb/util';
|
|
2
|
-
import { type Observable } from 'rxjs';
|
|
3
|
-
import { type LoadingContextEvent } from './loading.context';
|
|
4
|
-
import { type AbstractLoadingEventForLoadingPairConfig, type AbstractLoadingStateContext, AbstractLoadingStateContextInstance, type LoadingStateContextInstanceInputConfig } from './loading.context.state';
|
|
5
|
-
import { type LoadingState } from './loading.state';
|
|
6
|
-
export interface LoadingStateContextEvent<T = unknown> extends LoadingContextEvent {
|
|
7
|
-
value?: Maybe<T>;
|
|
8
|
-
}
|
|
9
|
-
export type LoadingEventForLoadingPairConfig<S extends LoadingState = LoadingState> = AbstractLoadingEventForLoadingPairConfig<S>;
|
|
10
|
-
export interface LoadingStateContext<T = unknown, S extends LoadingState<T> = LoadingState<T>> extends AbstractLoadingStateContext<T, S, LoadingStateContextEvent<T>> {
|
|
11
|
-
readonly list$: Observable<T[]>;
|
|
12
|
-
readonly values$: Observable<T[]>;
|
|
13
|
-
readonly isEmpty$: Observable<boolean>;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* LoadingContext implementation for a LoadingState.
|
|
17
|
-
*/
|
|
18
|
-
export declare class LoadingStateContextInstance<T = unknown, S extends LoadingState<T> = LoadingState<T>> extends AbstractLoadingStateContextInstance<T, S, LoadingStateContextEvent<T>, LoadingEventForLoadingPairConfig<S>> {
|
|
19
|
-
readonly value$: Observable<Maybe<T>>;
|
|
20
|
-
readonly valueAfterLoaded$: Observable<Maybe<T>>;
|
|
21
|
-
protected loadingEventForLoadingPair(pair: S, { showLoadingOnNoValue }?: LoadingEventForLoadingPairConfig): LoadingStateContextEvent<T>;
|
|
22
|
-
}
|
|
23
|
-
export declare function loadingStateContext<T = unknown, S extends LoadingState<T> = LoadingState<T>>(config: LoadingStateContextInstanceInputConfig<S, LoadingEventForLoadingPairConfig<S>>): LoadingStateContextInstance<T, S>;
|