reactjrx 1.107.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 CHANGED
@@ -747,6 +747,32 @@ function useMutation$(options, queryClient) {
747
747
  }, [status, isPending, isError, isSuccess, isIdle, stateSubject]);
748
748
  return { ...result, state$: stateSubject.current };
749
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
+ }
750
776
  function hasObjectPrototype(o) {
751
777
  return Object.prototype.toString.call(o) === "[object Object]";
752
778
  }
@@ -3528,4 +3554,5 @@ exports.useSignalValue = useSignalValue;
3528
3554
  exports.useSubject = useSubject;
3529
3555
  exports.useSubscribe = useSubscribe;
3530
3556
  exports.useSubscribeEffect = useSubscribeEffect;
3557
+ exports.useSwitchMutation$ = useSwitchMutation$;
3531
3558
  exports.useUnmountObservable = useUnmountObservable;
package/dist/index.d.ts CHANGED
@@ -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, takeUntil, shareReplay, ignoreElements, fromEvent, noop as noop$1, pairwise, NEVER, delay, interval, withLatestFrom, retry, iif, isEmpty, concat, toArray, combineLatest, endWith, lastValueFrom } from "rxjs";
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";
@@ -729,6 +729,32 @@ function useMutation$(options, queryClient) {
729
729
  }, [status, isPending, isError, isSuccess, isIdle, stateSubject]);
730
730
  return { ...result, state$: stateSubject.current };
731
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
+ }
732
758
  function hasObjectPrototype(o) {
733
759
  return Object.prototype.toString.call(o) === "[object Object]";
734
760
  }
@@ -3511,5 +3537,6 @@ export {
3511
3537
  useSubject,
3512
3538
  useSubscribe,
3513
3539
  useSubscribeEffect,
3540
+ useSwitchMutation$,
3514
3541
  useUnmountObservable
3515
3542
  };
@@ -1,8 +1,9 @@
1
1
  import { DefaultError, QueryClient, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
2
2
  import { Observable } from 'rxjs';
3
- export declare function useMutation$<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: Omit<UseMutationOptions<TData, TError, TVariables, TContext>, "mutationFn"> & {
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
- }, queryClient?: QueryClient): {
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reactjrx",
3
3
  "private": false,
4
- "version": "1.107.0",
4
+ "version": "1.108.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"