floppy-disk 2.14.0 → 2.15.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.
|
@@ -4,7 +4,7 @@ import { createStore } from './create-store';
|
|
|
4
4
|
* @see https://floppy-disk.vercel.app/docs/api#createmutation
|
|
5
5
|
*/
|
|
6
6
|
export const createMutation = (mutationFn, options = {}) => {
|
|
7
|
-
const { onMutate = noop, onSuccess = noop, onError
|
|
7
|
+
const { onMutate = noop, onSuccess = noop, onError, onSettled = noop, ...createStoreOptions } = options;
|
|
8
8
|
const useMutation = createStore(({ set, get }) => ({
|
|
9
9
|
isWaiting: false,
|
|
10
10
|
isSuccess: false,
|
|
@@ -40,7 +40,10 @@ export const createMutation = (mutationFn, options = {}) => {
|
|
|
40
40
|
error,
|
|
41
41
|
errorUpdatedAt: Date.now(),
|
|
42
42
|
});
|
|
43
|
-
onError
|
|
43
|
+
if (onError)
|
|
44
|
+
onError(error, variables, stateBeforeMutate);
|
|
45
|
+
else
|
|
46
|
+
console.error(error, variables, get());
|
|
44
47
|
resolve({ error, variables });
|
|
45
48
|
})
|
|
46
49
|
.finally(() => {
|
|
@@ -40,7 +40,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
40
40
|
const defaultFetchOnReconnect = options.fetchOnMount ?? true;
|
|
41
41
|
const { onFirstSubscribe = noop, onSubscribe = noop, onLastUnsubscribe = noop, onBeforeChangeKey = noop, defaultDeps = useQueryDefaultDeps, select = identityFn, staleTime = 3000, // 3 seconds
|
|
42
42
|
fetchOnMount = true, fetchOnWindowFocus = defaultFetchOnWindowFocus, fetchOnReconnect = defaultFetchOnReconnect, enabled = true, retry = 1, retryDelay = 2000, // 2 seconds
|
|
43
|
-
keepPreviousData, getNextPageParam = () => undefined, onSuccess = noop, onError
|
|
43
|
+
keepPreviousData, getNextPageParam = () => undefined, onSuccess = noop, onError, onSettled = noop, cacheTime = 5 * 60 * 1000, refetchInterval = false, ...createStoresOptions } = options;
|
|
44
44
|
const retryTimeoutId = new Map();
|
|
45
45
|
const retryNextPageTimeoutId = new Map();
|
|
46
46
|
const resetTimeoutId = new Map();
|
|
@@ -167,7 +167,10 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
167
167
|
pageParam,
|
|
168
168
|
hasNextPage: hasValue(pageParam),
|
|
169
169
|
});
|
|
170
|
-
onError
|
|
170
|
+
if (onError)
|
|
171
|
+
onError(error, stateBeforeCallQuery);
|
|
172
|
+
else
|
|
173
|
+
console.error(error, get());
|
|
171
174
|
onSettled(stateBeforeCallQuery);
|
|
172
175
|
innerResolve(get());
|
|
173
176
|
});
|
|
@@ -235,7 +238,10 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
235
238
|
error,
|
|
236
239
|
errorUpdatedAt: Date.now(),
|
|
237
240
|
});
|
|
238
|
-
onError
|
|
241
|
+
if (onError)
|
|
242
|
+
onError(error, stateBeforeCallQuery);
|
|
243
|
+
else
|
|
244
|
+
console.error(error, get());
|
|
239
245
|
onSettled(stateBeforeCallQuery);
|
|
240
246
|
resolve(get());
|
|
241
247
|
});
|
|
@@ -7,7 +7,7 @@ const create_store_1 = require("./create-store");
|
|
|
7
7
|
* @see https://floppy-disk.vercel.app/docs/api#createmutation
|
|
8
8
|
*/
|
|
9
9
|
const createMutation = (mutationFn, options = {}) => {
|
|
10
|
-
const { onMutate = utils_1.noop, onSuccess = utils_1.noop, onError
|
|
10
|
+
const { onMutate = utils_1.noop, onSuccess = utils_1.noop, onError, onSettled = utils_1.noop, ...createStoreOptions } = options;
|
|
11
11
|
const useMutation = (0, create_store_1.createStore)(({ set, get }) => ({
|
|
12
12
|
isWaiting: false,
|
|
13
13
|
isSuccess: false,
|
|
@@ -43,7 +43,10 @@ const createMutation = (mutationFn, options = {}) => {
|
|
|
43
43
|
error,
|
|
44
44
|
errorUpdatedAt: Date.now(),
|
|
45
45
|
});
|
|
46
|
-
onError
|
|
46
|
+
if (onError)
|
|
47
|
+
onError(error, variables, stateBeforeMutate);
|
|
48
|
+
else
|
|
49
|
+
console.error(error, variables, get());
|
|
47
50
|
resolve({ error, variables });
|
|
48
51
|
})
|
|
49
52
|
.finally(() => {
|
|
@@ -43,7 +43,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
43
43
|
const defaultFetchOnReconnect = options.fetchOnMount ?? true;
|
|
44
44
|
const { onFirstSubscribe = utils_1.noop, onSubscribe = utils_1.noop, onLastUnsubscribe = utils_1.noop, onBeforeChangeKey = utils_1.noop, defaultDeps = useQueryDefaultDeps, select = utils_1.identityFn, staleTime = 3000, // 3 seconds
|
|
45
45
|
fetchOnMount = true, fetchOnWindowFocus = defaultFetchOnWindowFocus, fetchOnReconnect = defaultFetchOnReconnect, enabled = true, retry = 1, retryDelay = 2000, // 2 seconds
|
|
46
|
-
keepPreviousData, getNextPageParam = () => undefined, onSuccess = utils_1.noop, onError
|
|
46
|
+
keepPreviousData, getNextPageParam = () => undefined, onSuccess = utils_1.noop, onError, onSettled = utils_1.noop, cacheTime = 5 * 60 * 1000, refetchInterval = false, ...createStoresOptions } = options;
|
|
47
47
|
const retryTimeoutId = new Map();
|
|
48
48
|
const retryNextPageTimeoutId = new Map();
|
|
49
49
|
const resetTimeoutId = new Map();
|
|
@@ -170,7 +170,10 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
170
170
|
pageParam,
|
|
171
171
|
hasNextPage: (0, utils_1.hasValue)(pageParam),
|
|
172
172
|
});
|
|
173
|
-
onError
|
|
173
|
+
if (onError)
|
|
174
|
+
onError(error, stateBeforeCallQuery);
|
|
175
|
+
else
|
|
176
|
+
console.error(error, get());
|
|
174
177
|
onSettled(stateBeforeCallQuery);
|
|
175
178
|
innerResolve(get());
|
|
176
179
|
});
|
|
@@ -238,7 +241,10 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
238
241
|
error,
|
|
239
242
|
errorUpdatedAt: Date.now(),
|
|
240
243
|
});
|
|
241
|
-
onError
|
|
244
|
+
if (onError)
|
|
245
|
+
onError(error, stateBeforeCallQuery);
|
|
246
|
+
else
|
|
247
|
+
console.error(error, get());
|
|
242
248
|
onSettled(stateBeforeCallQuery);
|
|
243
249
|
resolve(get());
|
|
244
250
|
});
|