reactjrx 1.109.0 → 1.110.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 +13 -12
- package/dist/index.js +13 -12
- package/dist/lib/queries/useSwitchMutation$.d.ts +4 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -742,11 +742,7 @@ function useQuery$(options, queryClient) {
|
|
|
742
742
|
() => typeof options.queryFn === "function" ? options.queryFn(context) : options.queryFn
|
|
743
743
|
);
|
|
744
744
|
const queryHash = reactQuery.hashKey(context.queryKey);
|
|
745
|
-
const queryCacheEntry = queryClient$.getQuery(queryHash) ?? queryClient$.setQuery(
|
|
746
|
-
context.queryKey,
|
|
747
|
-
getSource(),
|
|
748
|
-
context.signal
|
|
749
|
-
);
|
|
745
|
+
const queryCacheEntry = queryClient$.getQuery(queryHash) ?? queryClient$.setQuery(context.queryKey, getSource(), context.signal);
|
|
750
746
|
const query$ = queryCacheEntry.query$;
|
|
751
747
|
query$.pipe(
|
|
752
748
|
rxjs.take(1),
|
|
@@ -762,6 +758,9 @@ function useQuery$(options, queryClient) {
|
|
|
762
758
|
},
|
|
763
759
|
complete: () => {
|
|
764
760
|
if ((queryCacheEntry == null ? void 0 : queryCacheEntry.lastData) === void 0) {
|
|
761
|
+
if (queryCacheEntry.signal.aborted) {
|
|
762
|
+
return resolve(void 0);
|
|
763
|
+
}
|
|
765
764
|
console.log(
|
|
766
765
|
`cancelled due to stream completing without data for query ${queryHash}`,
|
|
767
766
|
queryCacheEntry == null ? void 0 : queryCacheEntry.lastData
|
|
@@ -836,12 +835,7 @@ function useMutation$(options, queryClient) {
|
|
|
836
835
|
}
|
|
837
836
|
function useSwitchMutation$(options, queryClient) {
|
|
838
837
|
const [cancel$, cancel] = useObservableCallback();
|
|
839
|
-
const {
|
|
840
|
-
mutate,
|
|
841
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
842
|
-
mutateAsync: _removed,
|
|
843
|
-
...rest
|
|
844
|
-
} = useMutation$(
|
|
838
|
+
const { mutate, mutateAsync, ...rest } = useMutation$(
|
|
845
839
|
{
|
|
846
840
|
...options,
|
|
847
841
|
mutationFn: (variables) => {
|
|
@@ -858,7 +852,14 @@ function useSwitchMutation$(options, queryClient) {
|
|
|
858
852
|
},
|
|
859
853
|
[mutate, cancel]
|
|
860
854
|
);
|
|
861
|
-
|
|
855
|
+
const mutateAsyncSwitch = React.useCallback(
|
|
856
|
+
(variables) => {
|
|
857
|
+
cancel();
|
|
858
|
+
return mutateAsync(variables);
|
|
859
|
+
},
|
|
860
|
+
[mutateAsync, cancel]
|
|
861
|
+
);
|
|
862
|
+
return { ...rest, mutate: mutateSwitch, mutateAsync: mutateAsyncSwitch };
|
|
862
863
|
}
|
|
863
864
|
function hasObjectPrototype(o) {
|
|
864
865
|
return Object.prototype.toString.call(o) === "[object Object]";
|
package/dist/index.js
CHANGED
|
@@ -724,11 +724,7 @@ function useQuery$(options, queryClient) {
|
|
|
724
724
|
() => typeof options.queryFn === "function" ? options.queryFn(context) : options.queryFn
|
|
725
725
|
);
|
|
726
726
|
const queryHash = hashKey$1(context.queryKey);
|
|
727
|
-
const queryCacheEntry = queryClient$.getQuery(queryHash) ?? queryClient$.setQuery(
|
|
728
|
-
context.queryKey,
|
|
729
|
-
getSource(),
|
|
730
|
-
context.signal
|
|
731
|
-
);
|
|
727
|
+
const queryCacheEntry = queryClient$.getQuery(queryHash) ?? queryClient$.setQuery(context.queryKey, getSource(), context.signal);
|
|
732
728
|
const query$ = queryCacheEntry.query$;
|
|
733
729
|
query$.pipe(
|
|
734
730
|
take(1),
|
|
@@ -744,6 +740,9 @@ function useQuery$(options, queryClient) {
|
|
|
744
740
|
},
|
|
745
741
|
complete: () => {
|
|
746
742
|
if ((queryCacheEntry == null ? void 0 : queryCacheEntry.lastData) === void 0) {
|
|
743
|
+
if (queryCacheEntry.signal.aborted) {
|
|
744
|
+
return resolve(void 0);
|
|
745
|
+
}
|
|
747
746
|
console.log(
|
|
748
747
|
`cancelled due to stream completing without data for query ${queryHash}`,
|
|
749
748
|
queryCacheEntry == null ? void 0 : queryCacheEntry.lastData
|
|
@@ -818,12 +817,7 @@ function useMutation$(options, queryClient) {
|
|
|
818
817
|
}
|
|
819
818
|
function useSwitchMutation$(options, queryClient) {
|
|
820
819
|
const [cancel$, cancel] = useObservableCallback();
|
|
821
|
-
const {
|
|
822
|
-
mutate,
|
|
823
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
824
|
-
mutateAsync: _removed,
|
|
825
|
-
...rest
|
|
826
|
-
} = useMutation$(
|
|
820
|
+
const { mutate, mutateAsync, ...rest } = useMutation$(
|
|
827
821
|
{
|
|
828
822
|
...options,
|
|
829
823
|
mutationFn: (variables) => {
|
|
@@ -840,7 +834,14 @@ function useSwitchMutation$(options, queryClient) {
|
|
|
840
834
|
},
|
|
841
835
|
[mutate, cancel]
|
|
842
836
|
);
|
|
843
|
-
|
|
837
|
+
const mutateAsyncSwitch = useCallback(
|
|
838
|
+
(variables) => {
|
|
839
|
+
cancel();
|
|
840
|
+
return mutateAsync(variables);
|
|
841
|
+
},
|
|
842
|
+
[mutateAsync, cancel]
|
|
843
|
+
);
|
|
844
|
+
return { ...rest, mutate: mutateSwitch, mutateAsync: mutateAsyncSwitch };
|
|
844
845
|
}
|
|
845
846
|
function hasObjectPrototype(o) {
|
|
846
847
|
return Object.prototype.toString.call(o) === "[object Object]";
|
|
@@ -2,6 +2,7 @@ import { DefaultError, QueryClient } from '@tanstack/react-query';
|
|
|
2
2
|
import { UseMutation$Options } from './useMutation$';
|
|
3
3
|
export declare function useSwitchMutation$<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: UseMutation$Options<TData | null, TError, TVariables, TContext>, queryClient?: QueryClient): {
|
|
4
4
|
mutate: (variables: TVariables) => void;
|
|
5
|
+
mutateAsync: (variables: TVariables) => Promise<TData | null>;
|
|
5
6
|
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, TVariables, TContext>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
6
7
|
data: undefined;
|
|
7
8
|
variables: undefined;
|
|
@@ -19,6 +20,7 @@ export declare function useSwitchMutation$<TData = unknown, TError = DefaultErro
|
|
|
19
20
|
submittedAt: number;
|
|
20
21
|
} | {
|
|
21
22
|
mutate: (variables: TVariables) => void;
|
|
23
|
+
mutateAsync: (variables: TVariables) => Promise<TData | null>;
|
|
22
24
|
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, TVariables, TContext>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
23
25
|
data: undefined;
|
|
24
26
|
variables: TVariables;
|
|
@@ -36,6 +38,7 @@ export declare function useSwitchMutation$<TData = unknown, TError = DefaultErro
|
|
|
36
38
|
submittedAt: number;
|
|
37
39
|
} | {
|
|
38
40
|
mutate: (variables: TVariables) => void;
|
|
41
|
+
mutateAsync: (variables: TVariables) => Promise<TData | null>;
|
|
39
42
|
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, TVariables, TContext>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
40
43
|
data: undefined;
|
|
41
44
|
error: TError;
|
|
@@ -53,6 +56,7 @@ export declare function useSwitchMutation$<TData = unknown, TError = DefaultErro
|
|
|
53
56
|
submittedAt: number;
|
|
54
57
|
} | {
|
|
55
58
|
mutate: (variables: TVariables) => void;
|
|
59
|
+
mutateAsync: (variables: TVariables) => Promise<TData | null>;
|
|
56
60
|
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, TVariables, TContext>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
57
61
|
data: TData | null;
|
|
58
62
|
error: null;
|