reactjrx 1.31.1 → 1.32.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 +3 -2
- package/dist/index.js +3 -2
- package/dist/lib/queries/useMutation.d.ts +6 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -509,8 +509,9 @@ function useMutation(query, mapOperatorOrOptions, options = {}) {
|
|
|
509
509
|
rxjs.first(),
|
|
510
510
|
rxjs.map((data) => ({ data, isError: false })),
|
|
511
511
|
rxjs.catchError((error) => {
|
|
512
|
+
console.error(error);
|
|
512
513
|
if (optionsRef.current.onError != null) {
|
|
513
|
-
optionsRef.current.onError(error);
|
|
514
|
+
optionsRef.current.onError(error, args);
|
|
514
515
|
}
|
|
515
516
|
return rxjs.of({ data: error, isError: true });
|
|
516
517
|
})
|
|
@@ -520,7 +521,7 @@ function useMutation(query, mapOperatorOrOptions, options = {}) {
|
|
|
520
521
|
rxjs.map(([{ data, isError }, isLastMutationCalled2]) => {
|
|
521
522
|
if (!isError) {
|
|
522
523
|
if (optionsRef.current.onSuccess != null)
|
|
523
|
-
optionsRef.current.onSuccess(data);
|
|
524
|
+
optionsRef.current.onSuccess(data, args);
|
|
524
525
|
}
|
|
525
526
|
if (isLastMutationCalled2) {
|
|
526
527
|
return isError ? {
|
package/dist/index.js
CHANGED
|
@@ -507,8 +507,9 @@ function useMutation(query, mapOperatorOrOptions, options = {}) {
|
|
|
507
507
|
first(),
|
|
508
508
|
map((data) => ({ data, isError: false })),
|
|
509
509
|
catchError((error) => {
|
|
510
|
+
console.error(error);
|
|
510
511
|
if (optionsRef.current.onError != null) {
|
|
511
|
-
optionsRef.current.onError(error);
|
|
512
|
+
optionsRef.current.onError(error, args);
|
|
512
513
|
}
|
|
513
514
|
return of({ data: error, isError: true });
|
|
514
515
|
})
|
|
@@ -518,7 +519,7 @@ function useMutation(query, mapOperatorOrOptions, options = {}) {
|
|
|
518
519
|
map(([{ data, isError }, isLastMutationCalled2]) => {
|
|
519
520
|
if (!isError) {
|
|
520
521
|
if (optionsRef.current.onSuccess != null)
|
|
521
|
-
optionsRef.current.onSuccess(data);
|
|
522
|
+
optionsRef.current.onSuccess(data, args);
|
|
522
523
|
}
|
|
523
524
|
if (isLastMutationCalled2) {
|
|
524
525
|
return isError ? {
|
|
@@ -4,20 +4,20 @@ interface QueryState<R> {
|
|
|
4
4
|
status: "idle" | "loading" | "error" | "success";
|
|
5
5
|
error: unknown;
|
|
6
6
|
}
|
|
7
|
-
export interface MutationOptions<
|
|
7
|
+
export interface MutationOptions<Result, Params> {
|
|
8
8
|
retry?: false | number | ((attempt: number, error: unknown) => boolean);
|
|
9
9
|
/**
|
|
10
10
|
* Called for every mutation 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
|
-
onError?: (error: unknown) => void;
|
|
14
|
+
onError?: (error: unknown, params: Params) => void;
|
|
15
15
|
/**
|
|
16
16
|
* Called for every mutation 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
|
-
onSuccess?: (data:
|
|
20
|
+
onSuccess?: (data: Result, params: Params) => void;
|
|
21
21
|
/**
|
|
22
22
|
* When true, any running mutation will be cancelled (when possible) on unmount.
|
|
23
23
|
* You need to handle it yourself for promises if needed.
|
|
@@ -33,7 +33,7 @@ export interface MutationOptions<R> {
|
|
|
33
33
|
* Only use for debugging.
|
|
34
34
|
* It is not the main subscription hook, only the one following the trigger.
|
|
35
35
|
*/
|
|
36
|
-
triggerHook?: MonoTypeOperatorFunction<Partial<QueryState<
|
|
36
|
+
triggerHook?: MonoTypeOperatorFunction<Partial<QueryState<Result>> | undefined>;
|
|
37
37
|
}
|
|
38
38
|
interface Result<A, R> {
|
|
39
39
|
status: "idle" | "loading" | "error" | "success";
|
|
@@ -77,6 +77,6 @@ interface Result<A, R> {
|
|
|
77
77
|
* Result correspond to the current running mutation.
|
|
78
78
|
*/
|
|
79
79
|
type MapOperator = "switch" | "concat" | "merge";
|
|
80
|
-
export declare function useMutation<A = void, R = undefined>(query: (args: A) => Promise<R> | Observable<R>, mapOperatorOrOptions?: MapOperator, options?: MutationOptions<R>): Result<A, R>;
|
|
81
|
-
export declare function useMutation<A = void, R = undefined>(query: (args: A) => Promise<R> | Observable<R>, mapOperatorOrOptions?: MutationOptions<R>): Result<A, R>;
|
|
80
|
+
export declare function useMutation<A = void, R = undefined>(query: (args: A) => Promise<R> | Observable<R>, mapOperatorOrOptions?: MapOperator, options?: MutationOptions<R, A>): Result<A, R>;
|
|
81
|
+
export declare function useMutation<A = void, R = undefined>(query: (args: A) => Promise<R> | Observable<R>, mapOperatorOrOptions?: MutationOptions<R, A>): Result<A, R>;
|
|
82
82
|
export {};
|