reactjrx 1.106.0 → 1.108.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 +32 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +33 -7
- package/dist/lib/binding/useObservableCallback.d.ts +5 -0
- package/dist/lib/queries/useMutation$.d.ts +3 -2
- package/dist/lib/queries/useSwitchMutation$.d.ts +71 -0
- package/package.json +1 -1
- package/dist/lib/binding/useObservableEvent.d.ts +0 -4
package/dist/index.cjs
CHANGED
|
@@ -161,9 +161,8 @@ const useSubject = ({
|
|
|
161
161
|
}, [completeOnUnmountRef, onBeforeCompleteRef, subject]);
|
|
162
162
|
return subject;
|
|
163
163
|
};
|
|
164
|
-
const
|
|
164
|
+
const useObservableCallback = () => {
|
|
165
165
|
const subject = useSubject();
|
|
166
|
-
const event$ = useLiveRef(subject.current.asObservable());
|
|
167
166
|
const trigger = React.useCallback(
|
|
168
167
|
(arg) => {
|
|
169
168
|
subject.current.next(arg);
|
|
@@ -171,7 +170,7 @@ const useObserveCallback = () => {
|
|
|
171
170
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
172
171
|
[]
|
|
173
172
|
);
|
|
174
|
-
return [
|
|
173
|
+
return [subject.current, trigger];
|
|
175
174
|
};
|
|
176
175
|
const useBehaviorSubject = (state) => {
|
|
177
176
|
const subject = useConstant(() => new rxjs.BehaviorSubject(state));
|
|
@@ -722,7 +721,7 @@ function useMutation$(options, queryClient) {
|
|
|
722
721
|
const source = typeof options.mutationFn === "function" ? options.mutationFn(variables) : options.mutationFn;
|
|
723
722
|
source.pipe(rxjs.take(1)).subscribe({
|
|
724
723
|
next: (data) => {
|
|
725
|
-
lastData = data;
|
|
724
|
+
lastData = { value: data };
|
|
726
725
|
},
|
|
727
726
|
error: (error) => {
|
|
728
727
|
reject(error);
|
|
@@ -730,7 +729,7 @@ function useMutation$(options, queryClient) {
|
|
|
730
729
|
complete: () => {
|
|
731
730
|
if (lastData === void 0)
|
|
732
731
|
return reject(new Error("Stream completed without any data"));
|
|
733
|
-
resolve(lastData);
|
|
732
|
+
resolve(lastData.value);
|
|
734
733
|
}
|
|
735
734
|
});
|
|
736
735
|
});
|
|
@@ -748,6 +747,32 @@ function useMutation$(options, queryClient) {
|
|
|
748
747
|
}, [status, isPending, isError, isSuccess, isIdle, stateSubject]);
|
|
749
748
|
return { ...result, state$: stateSubject.current };
|
|
750
749
|
}
|
|
750
|
+
function useSwitchMutation$(options, queryClient) {
|
|
751
|
+
const [cancel$, cancel] = useObservableCallback();
|
|
752
|
+
const {
|
|
753
|
+
mutate,
|
|
754
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
755
|
+
mutateAsync: _removed,
|
|
756
|
+
...rest
|
|
757
|
+
} = useMutation$(
|
|
758
|
+
{
|
|
759
|
+
...options,
|
|
760
|
+
mutationFn: (variables) => {
|
|
761
|
+
const source = typeof options.mutationFn === "function" ? options.mutationFn(variables) : options.mutationFn;
|
|
762
|
+
return source.pipe(rxjs.takeUntil(cancel$), rxjs.defaultIfEmpty(null));
|
|
763
|
+
}
|
|
764
|
+
},
|
|
765
|
+
queryClient
|
|
766
|
+
);
|
|
767
|
+
const mutateSwitch = React.useCallback(
|
|
768
|
+
(variables) => {
|
|
769
|
+
cancel();
|
|
770
|
+
mutate(variables);
|
|
771
|
+
},
|
|
772
|
+
[mutate, cancel]
|
|
773
|
+
);
|
|
774
|
+
return { ...rest, mutate: mutateSwitch };
|
|
775
|
+
}
|
|
751
776
|
function hasObjectPrototype(o) {
|
|
752
777
|
return Object.prototype.toString.call(o) === "[object Object]";
|
|
753
778
|
}
|
|
@@ -3517,9 +3542,9 @@ exports.useLiveRef = useLiveRef;
|
|
|
3517
3542
|
exports.useMount = useMount;
|
|
3518
3543
|
exports.useMutation = useMutation;
|
|
3519
3544
|
exports.useMutation$ = useMutation$;
|
|
3545
|
+
exports.useObservableCallback = useObservableCallback;
|
|
3520
3546
|
exports.useObservableState = useObservableState;
|
|
3521
3547
|
exports.useObserve = useObserve;
|
|
3522
|
-
exports.useObserveCallback = useObserveCallback;
|
|
3523
3548
|
exports.usePersistSignals = usePersistSignals;
|
|
3524
3549
|
exports.useQuery = useQuery;
|
|
3525
3550
|
exports.useQuery$ = useQuery$;
|
|
@@ -3529,4 +3554,5 @@ exports.useSignalValue = useSignalValue;
|
|
|
3529
3554
|
exports.useSubject = useSubject;
|
|
3530
3555
|
exports.useSubscribe = useSubscribe;
|
|
3531
3556
|
exports.useSubscribeEffect = useSubscribeEffect;
|
|
3557
|
+
exports.useSwitchMutation$ = useSwitchMutation$;
|
|
3532
3558
|
exports.useUnmountObservable = useUnmountObservable;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './lib/binding/useObserve';
|
|
2
2
|
export * from './lib/binding/useSubscribe';
|
|
3
|
-
export * from './lib/binding/
|
|
3
|
+
export * from './lib/binding/useObservableCallback';
|
|
4
4
|
export * from './lib/binding/useObservableState';
|
|
5
5
|
export * from './lib/binding/useSubject';
|
|
6
6
|
export * from './lib/binding/useBehaviorSubject';
|
|
@@ -16,6 +16,7 @@ export { type SignalPersistenceConfig } from './lib/state/persistance/types';
|
|
|
16
16
|
export * from './lib/utils';
|
|
17
17
|
export * from './lib/queries/useQuery$';
|
|
18
18
|
export * from './lib/queries/useMutation$';
|
|
19
|
+
export * from './lib/queries/useSwitchMutation$';
|
|
19
20
|
export * from './lib/deprecated/react/mutations/useMutation';
|
|
20
21
|
export * from './lib/deprecated/react/queries/useQuery';
|
|
21
22
|
export * from './lib/deprecated/react/useQueryClient';
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
|
|
|
11
11
|
var _trigger$, _mutationRunner, _currentMutationSubject, _visibility$, _focusedSubject, _client, _currentQuery, _fetchSubject, _currentQueryInitialState, _lastResult, _lastQueryWithDefinedData, _observers, _observerCount, _cancelSubject, _executeSubject, _store, _defaultOptions, _initialState, _notifySubject, _store2, _mutationCache, _queryCache, _mutationDefaults, _queryDefaults, _defaultOptions2;
|
|
12
12
|
import * as React from "react";
|
|
13
13
|
import { useRef, useMemo, useCallback, useSyncExternalStore, useEffect, useState, createContext, memo, useContext } from "react";
|
|
14
|
-
import { isObservable, from, of, defer, startWith, identity, distinctUntilChanged, tap, catchError, EMPTY, Subject, BehaviorSubject, skip, first, map, switchMap, zip, share, merge, throttleTime, asyncScheduler, concatMap, scan, throwError, timer, finalize, take, Observable, takeWhile, filter, last, mergeMap as mergeMap$1,
|
|
14
|
+
import { isObservable, from, of, defer, startWith, identity, distinctUntilChanged, tap, catchError, EMPTY, Subject, BehaviorSubject, skip, first, map, switchMap, zip, share, merge, throttleTime, asyncScheduler, concatMap, scan, throwError, timer, finalize, take, takeUntil, defaultIfEmpty, Observable, takeWhile, filter, last, mergeMap as mergeMap$1, shareReplay, ignoreElements, fromEvent, noop as noop$1, pairwise, NEVER, delay, interval, withLatestFrom, retry, iif, isEmpty, concat, toArray, combineLatest, endWith, lastValueFrom } from "rxjs";
|
|
15
15
|
import { catchError as catchError$1, mergeMap, retryWhen, concatMap as concatMap$1, first as first$1, tap as tap$1 } from "rxjs/operators";
|
|
16
16
|
import { useQueryClient as useQueryClient$1, useQuery as useQuery$1, useMutation as useMutation$1 } from "@tanstack/react-query";
|
|
17
17
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
@@ -143,9 +143,8 @@ const useSubject = ({
|
|
|
143
143
|
}, [completeOnUnmountRef, onBeforeCompleteRef, subject]);
|
|
144
144
|
return subject;
|
|
145
145
|
};
|
|
146
|
-
const
|
|
146
|
+
const useObservableCallback = () => {
|
|
147
147
|
const subject = useSubject();
|
|
148
|
-
const event$ = useLiveRef(subject.current.asObservable());
|
|
149
148
|
const trigger = useCallback(
|
|
150
149
|
(arg) => {
|
|
151
150
|
subject.current.next(arg);
|
|
@@ -153,7 +152,7 @@ const useObserveCallback = () => {
|
|
|
153
152
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
154
153
|
[]
|
|
155
154
|
);
|
|
156
|
-
return [
|
|
155
|
+
return [subject.current, trigger];
|
|
157
156
|
};
|
|
158
157
|
const useBehaviorSubject = (state) => {
|
|
159
158
|
const subject = useConstant(() => new BehaviorSubject(state));
|
|
@@ -704,7 +703,7 @@ function useMutation$(options, queryClient) {
|
|
|
704
703
|
const source = typeof options.mutationFn === "function" ? options.mutationFn(variables) : options.mutationFn;
|
|
705
704
|
source.pipe(take(1)).subscribe({
|
|
706
705
|
next: (data) => {
|
|
707
|
-
lastData = data;
|
|
706
|
+
lastData = { value: data };
|
|
708
707
|
},
|
|
709
708
|
error: (error) => {
|
|
710
709
|
reject(error);
|
|
@@ -712,7 +711,7 @@ function useMutation$(options, queryClient) {
|
|
|
712
711
|
complete: () => {
|
|
713
712
|
if (lastData === void 0)
|
|
714
713
|
return reject(new Error("Stream completed without any data"));
|
|
715
|
-
resolve(lastData);
|
|
714
|
+
resolve(lastData.value);
|
|
716
715
|
}
|
|
717
716
|
});
|
|
718
717
|
});
|
|
@@ -730,6 +729,32 @@ function useMutation$(options, queryClient) {
|
|
|
730
729
|
}, [status, isPending, isError, isSuccess, isIdle, stateSubject]);
|
|
731
730
|
return { ...result, state$: stateSubject.current };
|
|
732
731
|
}
|
|
732
|
+
function useSwitchMutation$(options, queryClient) {
|
|
733
|
+
const [cancel$, cancel] = useObservableCallback();
|
|
734
|
+
const {
|
|
735
|
+
mutate,
|
|
736
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
737
|
+
mutateAsync: _removed,
|
|
738
|
+
...rest
|
|
739
|
+
} = useMutation$(
|
|
740
|
+
{
|
|
741
|
+
...options,
|
|
742
|
+
mutationFn: (variables) => {
|
|
743
|
+
const source = typeof options.mutationFn === "function" ? options.mutationFn(variables) : options.mutationFn;
|
|
744
|
+
return source.pipe(takeUntil(cancel$), defaultIfEmpty(null));
|
|
745
|
+
}
|
|
746
|
+
},
|
|
747
|
+
queryClient
|
|
748
|
+
);
|
|
749
|
+
const mutateSwitch = useCallback(
|
|
750
|
+
(variables) => {
|
|
751
|
+
cancel();
|
|
752
|
+
mutate(variables);
|
|
753
|
+
},
|
|
754
|
+
[mutate, cancel]
|
|
755
|
+
);
|
|
756
|
+
return { ...rest, mutate: mutateSwitch };
|
|
757
|
+
}
|
|
733
758
|
function hasObjectPrototype(o) {
|
|
734
759
|
return Object.prototype.toString.call(o) === "[object Object]";
|
|
735
760
|
}
|
|
@@ -3500,9 +3525,9 @@ export {
|
|
|
3500
3525
|
useMount,
|
|
3501
3526
|
useMutation,
|
|
3502
3527
|
useMutation$,
|
|
3528
|
+
useObservableCallback,
|
|
3503
3529
|
useObservableState,
|
|
3504
3530
|
useObserve,
|
|
3505
|
-
useObserveCallback,
|
|
3506
3531
|
usePersistSignals,
|
|
3507
3532
|
useQuery,
|
|
3508
3533
|
useQuery$,
|
|
@@ -3512,5 +3537,6 @@ export {
|
|
|
3512
3537
|
useSubject,
|
|
3513
3538
|
useSubscribe,
|
|
3514
3539
|
useSubscribeEffect,
|
|
3540
|
+
useSwitchMutation$,
|
|
3515
3541
|
useUnmountObservable
|
|
3516
3542
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { DefaultError, QueryClient, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
export
|
|
3
|
+
export type UseMutation$Options<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = Omit<UseMutationOptions<TData, TError, TVariables, TContext>, "mutationFn"> & {
|
|
4
4
|
mutationFn: ((variables: TVariables) => Observable<TData>) | Observable<TData>;
|
|
5
|
-
}
|
|
5
|
+
};
|
|
6
|
+
export declare function useMutation$<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: UseMutation$Options<TData, TError, TVariables, TContext>, queryClient?: QueryClient): {
|
|
6
7
|
state$: import('rxjs').BehaviorSubject<Pick<UseMutationResult<TData, TError, TVariables, TContext>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
7
8
|
data: undefined;
|
|
8
9
|
variables: undefined;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { DefaultError, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { UseMutation$Options } from './useMutation$';
|
|
3
|
+
export declare function useSwitchMutation$<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: UseMutation$Options<TData | null, TError, TVariables, TContext>, queryClient?: QueryClient): {
|
|
4
|
+
mutate: (variables: TVariables) => void;
|
|
5
|
+
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, TVariables, TContext>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
6
|
+
data: undefined;
|
|
7
|
+
variables: undefined;
|
|
8
|
+
error: null;
|
|
9
|
+
isError: false;
|
|
10
|
+
isIdle: true;
|
|
11
|
+
isPending: false;
|
|
12
|
+
isSuccess: false;
|
|
13
|
+
status: "idle";
|
|
14
|
+
reset: () => void;
|
|
15
|
+
context: TContext | undefined;
|
|
16
|
+
failureCount: number;
|
|
17
|
+
failureReason: TError | null;
|
|
18
|
+
isPaused: boolean;
|
|
19
|
+
submittedAt: number;
|
|
20
|
+
} | {
|
|
21
|
+
mutate: (variables: TVariables) => void;
|
|
22
|
+
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, TVariables, TContext>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
23
|
+
data: undefined;
|
|
24
|
+
variables: TVariables;
|
|
25
|
+
error: null;
|
|
26
|
+
isError: false;
|
|
27
|
+
isIdle: false;
|
|
28
|
+
isPending: true;
|
|
29
|
+
isSuccess: false;
|
|
30
|
+
status: "pending";
|
|
31
|
+
reset: () => void;
|
|
32
|
+
context: TContext | undefined;
|
|
33
|
+
failureCount: number;
|
|
34
|
+
failureReason: TError | null;
|
|
35
|
+
isPaused: boolean;
|
|
36
|
+
submittedAt: number;
|
|
37
|
+
} | {
|
|
38
|
+
mutate: (variables: TVariables) => void;
|
|
39
|
+
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, TVariables, TContext>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
40
|
+
data: undefined;
|
|
41
|
+
error: TError;
|
|
42
|
+
variables: TVariables;
|
|
43
|
+
isError: true;
|
|
44
|
+
isIdle: false;
|
|
45
|
+
isPending: false;
|
|
46
|
+
isSuccess: false;
|
|
47
|
+
status: "error";
|
|
48
|
+
reset: () => void;
|
|
49
|
+
context: TContext | undefined;
|
|
50
|
+
failureCount: number;
|
|
51
|
+
failureReason: TError | null;
|
|
52
|
+
isPaused: boolean;
|
|
53
|
+
submittedAt: number;
|
|
54
|
+
} | {
|
|
55
|
+
mutate: (variables: TVariables) => void;
|
|
56
|
+
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, TVariables, TContext>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
57
|
+
data: TData | null;
|
|
58
|
+
error: null;
|
|
59
|
+
variables: TVariables;
|
|
60
|
+
isError: false;
|
|
61
|
+
isIdle: false;
|
|
62
|
+
isPending: false;
|
|
63
|
+
isSuccess: true;
|
|
64
|
+
status: "success";
|
|
65
|
+
reset: () => void;
|
|
66
|
+
context: TContext | undefined;
|
|
67
|
+
failureCount: number;
|
|
68
|
+
failureReason: TError | null;
|
|
69
|
+
isPaused: boolean;
|
|
70
|
+
submittedAt: number;
|
|
71
|
+
};
|
package/package.json
CHANGED