use-abcd 0.0.2 → 0.1.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/useCrud.d.ts +17 -9
- package/dist/useCrud.js +389 -340
- package/package.json +5 -2
package/dist/useCrud.d.ts
CHANGED
|
@@ -52,14 +52,14 @@ export declare type FetchFn<T extends Item = Item> = (option: QueryOption) => Pr
|
|
|
52
52
|
|
|
53
53
|
export declare type Item = {
|
|
54
54
|
id: string;
|
|
55
|
-
} & Record<string,
|
|
55
|
+
} & Record<string, any>;
|
|
56
56
|
|
|
57
57
|
export declare type ItemWithState<T extends Item = Item> = {
|
|
58
58
|
data: T;
|
|
59
|
-
state:
|
|
59
|
+
state: TransitionStates;
|
|
60
60
|
optimistic: boolean;
|
|
61
61
|
errors: string[];
|
|
62
|
-
|
|
62
|
+
action?: [TransitionStates, T];
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
export declare type QueryOption = {
|
|
@@ -84,6 +84,8 @@ export declare type TransitionFn<T extends Item = Item> = (item: Partial<T>, opt
|
|
|
84
84
|
id: string;
|
|
85
85
|
}>;
|
|
86
86
|
|
|
87
|
+
export declare type TransitionStates = "create" | "update" | "delete" | "idle" | "error" | "changed";
|
|
88
|
+
|
|
87
89
|
export declare type Updater<T> = (updatable: T) => void;
|
|
88
90
|
|
|
89
91
|
/**
|
|
@@ -99,18 +101,21 @@ export declare function useCrud<T extends Item = Item, C extends Record<string,
|
|
|
99
101
|
items: {
|
|
100
102
|
id: string;
|
|
101
103
|
data: T;
|
|
102
|
-
state:
|
|
104
|
+
state: TransitionStates;
|
|
103
105
|
optimistic: boolean;
|
|
104
106
|
errors: string[];
|
|
105
|
-
|
|
107
|
+
action?: [TransitionStates, T];
|
|
106
108
|
}[];
|
|
107
109
|
metadata: unknown;
|
|
108
110
|
isLoading: boolean;
|
|
109
111
|
hasError: boolean;
|
|
110
112
|
errors: string[];
|
|
111
113
|
create: (item: Omit<T, "id">) => void;
|
|
112
|
-
update: (item: T
|
|
113
|
-
|
|
114
|
+
update: (item: ItemWithState<T>, updater: Updater<T>, isOptimistic?: boolean) => void;
|
|
115
|
+
change: (item: ItemWithState<T>, updater: Updater<T>) => void;
|
|
116
|
+
retry: (item: ItemWithState<T>) => void;
|
|
117
|
+
save: (item: ItemWithState<T>) => void;
|
|
118
|
+
remove: (item: ItemWithState<T>) => void;
|
|
114
119
|
cancelFetch: () => void;
|
|
115
120
|
cancelOperation: (id: string) => void;
|
|
116
121
|
};
|
|
@@ -126,8 +131,11 @@ export declare function useCrudOperations<T extends Item = Item, C extends Recor
|
|
|
126
131
|
fetch: () => void;
|
|
127
132
|
refetch: () => void;
|
|
128
133
|
create: (item: Omit<T, "id">) => void;
|
|
129
|
-
update: (item: T
|
|
130
|
-
|
|
134
|
+
update: (item: ItemWithState<T>, updater: Updater<T>, isOptimistic?: boolean) => void;
|
|
135
|
+
change: (item: ItemWithState<T>, updater: Updater<T>) => void;
|
|
136
|
+
save: (item: ItemWithState<T>) => void;
|
|
137
|
+
retry: (item: ItemWithState<T>) => void;
|
|
138
|
+
remove: (item: ItemWithState<T>) => void;
|
|
131
139
|
cancelFetch: () => void;
|
|
132
140
|
cancelOperation: (id: string) => void;
|
|
133
141
|
};
|