reactjrx 1.33.0 → 1.34.0
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/dist/index.cjs
CHANGED
|
@@ -459,13 +459,13 @@ function shallowEqual(objA, objB) {
|
|
|
459
459
|
}
|
|
460
460
|
return true;
|
|
461
461
|
}
|
|
462
|
-
function
|
|
462
|
+
function useAsyncQuery(query, mapOperatorOrOptions, options = {}) {
|
|
463
463
|
const queryRef = useLiveRef(query);
|
|
464
464
|
const triggerSubject = useSubject();
|
|
465
465
|
const resetSubject = useSubject({
|
|
466
466
|
/**
|
|
467
467
|
* @important
|
|
468
|
-
* Because
|
|
468
|
+
* Because async query can still run after unmount, the user might
|
|
469
469
|
* want to use reset for whatever reason. We will only manually complete
|
|
470
470
|
* this subject whenever the main query hook finalize.
|
|
471
471
|
*/
|
|
@@ -860,8 +860,8 @@ exports.getDelay = getDelay;
|
|
|
860
860
|
exports.retryBackoff = retryBackoff;
|
|
861
861
|
exports.signal = signal;
|
|
862
862
|
exports.trigger = trigger;
|
|
863
|
+
exports.useAsyncQuery = useAsyncQuery;
|
|
863
864
|
exports.useLiveRef = useLiveRef;
|
|
864
|
-
exports.useMutation = useMutation;
|
|
865
865
|
exports.useObserve = useObserve;
|
|
866
866
|
exports.useObserveCallback = useObserveCallback;
|
|
867
867
|
exports.usePersistSignalsContext = usePersistSignalsContext;
|
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export * from "./lib/state/persistance/createLocalforageAdapter";
|
|
|
15
15
|
export * from "./lib/utils/useUnmountObservable";
|
|
16
16
|
export * from "./lib/utils/retryBackoff";
|
|
17
17
|
export * from "./lib/utils/useLiveRef";
|
|
18
|
-
export * from "./lib/queries/
|
|
18
|
+
export * from "./lib/queries/useAsyncQuery";
|
|
19
19
|
export * from "./lib/queries/useQuery";
|
|
20
20
|
export * from "./lib/queries/useSubscribeEffect";
|
|
21
21
|
export { Provider as ReactjrxQueryProvider } from "./lib/queries/Provider";
|
package/dist/index.js
CHANGED
|
@@ -457,13 +457,13 @@ function shallowEqual(objA, objB) {
|
|
|
457
457
|
}
|
|
458
458
|
return true;
|
|
459
459
|
}
|
|
460
|
-
function
|
|
460
|
+
function useAsyncQuery(query, mapOperatorOrOptions, options = {}) {
|
|
461
461
|
const queryRef = useLiveRef(query);
|
|
462
462
|
const triggerSubject = useSubject();
|
|
463
463
|
const resetSubject = useSubject({
|
|
464
464
|
/**
|
|
465
465
|
* @important
|
|
466
|
-
* Because
|
|
466
|
+
* Because async query can still run after unmount, the user might
|
|
467
467
|
* want to use reset for whatever reason. We will only manually complete
|
|
468
468
|
* this subject whenever the main query hook finalize.
|
|
469
469
|
*/
|
|
@@ -859,8 +859,8 @@ export {
|
|
|
859
859
|
retryBackoff,
|
|
860
860
|
signal,
|
|
861
861
|
trigger,
|
|
862
|
+
useAsyncQuery,
|
|
862
863
|
useLiveRef,
|
|
863
|
-
useMutation,
|
|
864
864
|
useObserve,
|
|
865
865
|
useObserveCallback,
|
|
866
866
|
usePersistSignalsContext,
|
|
@@ -4,22 +4,22 @@ interface QueryState<R> {
|
|
|
4
4
|
status: "idle" | "loading" | "error" | "success";
|
|
5
5
|
error: unknown;
|
|
6
6
|
}
|
|
7
|
-
export interface
|
|
7
|
+
export interface AsyncQueryOptions<Result, Params> {
|
|
8
8
|
retry?: false | number | ((attempt: number, error: unknown) => boolean);
|
|
9
9
|
/**
|
|
10
|
-
* Called for every
|
|
10
|
+
* Called for every async query on error.
|
|
11
11
|
* `merge` mapping will run callback as they happen.
|
|
12
12
|
* Use `concat` if you need to run callbacks in order of calling.
|
|
13
13
|
*/
|
|
14
14
|
onError?: (error: unknown, params: Params) => void;
|
|
15
15
|
/**
|
|
16
|
-
* Called for every
|
|
16
|
+
* Called for every async query on success.
|
|
17
17
|
* `merge` mapping will run callback as they happen.
|
|
18
18
|
* Use `concat` if you need to run callbacks in order of calling.
|
|
19
19
|
*/
|
|
20
20
|
onSuccess?: (data: Result, params: Params) => void;
|
|
21
21
|
/**
|
|
22
|
-
* When true, any running
|
|
22
|
+
* When true, any running async query will be cancelled (when possible) on unmount.
|
|
23
23
|
* You need to handle it yourself for promises if needed.
|
|
24
24
|
* Callbacks will not be called as a result.
|
|
25
25
|
*
|
|
@@ -39,19 +39,19 @@ interface Result<A, R> {
|
|
|
39
39
|
status: "idle" | "loading" | "error" | "success";
|
|
40
40
|
isLoading: boolean;
|
|
41
41
|
/**
|
|
42
|
-
* If the latest
|
|
42
|
+
* If the latest async query is in a success state, data contains its result.
|
|
43
43
|
*
|
|
44
44
|
* @important
|
|
45
|
-
* The value does not automatically reset when a new
|
|
46
|
-
* when a new
|
|
45
|
+
* The value does not automatically reset when a new async query run. It will be updated
|
|
46
|
+
* when a new async query success or error.
|
|
47
47
|
*/
|
|
48
48
|
data: R | undefined;
|
|
49
49
|
/**
|
|
50
|
-
* If the latest
|
|
50
|
+
* If the latest async query is in a error state, error contains its error.
|
|
51
51
|
*
|
|
52
52
|
* @important
|
|
53
|
-
* The value does not automatically reset when a new
|
|
54
|
-
* when a new
|
|
53
|
+
* The value does not automatically reset when a new async query run. It will be updated
|
|
54
|
+
* when a new async query success or error.
|
|
55
55
|
*/
|
|
56
56
|
error: unknown | undefined;
|
|
57
57
|
mutate: (args: A) => void;
|
|
@@ -63,20 +63,20 @@ interface Result<A, R> {
|
|
|
63
63
|
* it when specific need arise.
|
|
64
64
|
*
|
|
65
65
|
* `merge`:
|
|
66
|
-
* Run each
|
|
67
|
-
* The result is always from the latest
|
|
66
|
+
* Run each async query as they are triggered without any cancellation or queue system.
|
|
67
|
+
* The result is always from the latest async query triggered, not necessarily
|
|
68
68
|
* the latest one running.
|
|
69
69
|
*
|
|
70
70
|
* `concat`:
|
|
71
|
-
* Unlike merge, it will trigger each
|
|
72
|
-
* a queue system. The result is not necessarily the last triggered
|
|
73
|
-
* but the current running
|
|
71
|
+
* Unlike merge, it will trigger each async query sequentially following
|
|
72
|
+
* a queue system. The result is not necessarily the last triggered async query
|
|
73
|
+
* but the current running async query.
|
|
74
74
|
*
|
|
75
75
|
* `switch`:
|
|
76
|
-
* Only run the latest
|
|
77
|
-
* Result correspond to the current running
|
|
76
|
+
* Only run the latest async query triggered and cancel any previously running one.
|
|
77
|
+
* Result correspond to the current running async query.
|
|
78
78
|
*/
|
|
79
79
|
type MapOperator = "switch" | "concat" | "merge";
|
|
80
|
-
export declare function
|
|
81
|
-
export declare function
|
|
80
|
+
export declare function useAsyncQuery<A = void, R = undefined>(query: (args: A) => Promise<R> | Observable<R>, mapOperatorOrOptions?: MapOperator, options?: AsyncQueryOptions<R, A>): Result<A, R>;
|
|
81
|
+
export declare function useAsyncQuery<A = void, R = undefined>(query: (args: A) => Promise<R> | Observable<R>, mapOperatorOrOptions?: AsyncQueryOptions<R, A>): Result<A, R>;
|
|
82
82
|
export {};
|