1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | interface UseMutationProps<T> {
|
7 | defaultValue: T;
|
8 | scenario?: Record<string, Array<keyof T>>;
|
9 | format?: {
|
10 | [P in keyof T]?: (value: T[P], data: T) => T[P];
|
11 | };
|
12 | }
|
13 |
|
14 | type SendProps<T = any, S = any> = {
|
15 | scenario?: string;
|
16 | service: (event?: import(".").EventSend<T>) => S;
|
17 | onSuccess?: (data: any) => void;
|
18 | onError?: (e: any) => void;
|
19 | onAlways?: () => void;
|
20 | };
|
21 |
|
22 | type UseMutation<T> = {
|
23 | processing: boolean;
|
24 | scenario: string;
|
25 | data: (scenario?: string | boolean) => Partial<T>;
|
26 | setData: (
|
27 | value: Partial<{ [key in import(".").DeepKeys<T>]: any }> | {}
|
28 | ) => void;
|
29 | increment: (
|
30 | value: Partial<{ [key in import(".").DeepKeys<T>]: any }> | {}
|
31 | ) => void;
|
32 | decrement: (
|
33 | value: Partial<{ [key in import(".").DeepKeys<T>]: any }> | {}
|
34 | ) => void;
|
35 | send: <F = UseMutation<T>["data"], S = any>(option?: SendProps<F>) => S;
|
36 | reset: () => void;
|
37 | cancel: () => void;
|
38 | value: <V = any>(key: import(".").DeepKeys<T>, defaultValue?: any) => V;
|
39 | add: (
|
40 | key: import(".").DeepKeys<T> | {},
|
41 | value: any,
|
42 | position?: "start" | "end" | number
|
43 | ) => void;
|
44 | upsert: (
|
45 | key: import(".").DeepKeys<T> | {},
|
46 | val: any,
|
47 | attr?: string[],
|
48 | position?: "start" | "end" | number
|
49 | ) => void;
|
50 | remove: (
|
51 | key: import(".").DeepKeys<T> | {},
|
52 | condition?: number | ((data: any) => boolean)
|
53 | ) => void;
|
54 | keys: (scenario?: boolean | string) => { name: string; keys: string[] }[];
|
55 | setScenario: (scenario: string) => void;
|
56 | };
|
57 |
|
58 | export default function useMutation<T = any>(
|
59 | props: UseMutationProps<T>
|
60 | ): UseMutation<T>;
|