floppy-disk 2.0.1-beta.1 → 2.0.1-beta.2
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/esm/preact/create-mutation.d.ts +3 -1
- package/esm/preact/create-query.d.ts +45 -25
- package/esm/preact/create-query.js +6 -2
- package/esm/react/create-mutation.d.ts +3 -1
- package/esm/react/create-query.d.ts +45 -25
- package/esm/react/create-query.js +6 -2
- package/lib/preact/create-mutation.d.ts +3 -1
- package/lib/preact/create-query.d.ts +45 -25
- package/lib/preact/create-query.js +6 -2
- package/lib/react/create-mutation.d.ts +3 -1
- package/lib/react/create-query.d.ts +45 -25
- package/lib/react/create-query.js +6 -2
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InitStoreOptions } from '../vanilla';
|
|
2
|
+
import { UseStore } from './create-store';
|
|
2
3
|
export type MutationState<TVar, TResponse = any, TError = unknown> = {
|
|
3
4
|
/**
|
|
4
5
|
* Network fetching status.
|
|
@@ -23,10 +24,11 @@ export type MutationState<TVar, TResponse = any, TError = unknown> = {
|
|
|
23
24
|
variables?: TVar;
|
|
24
25
|
}>;
|
|
25
26
|
};
|
|
27
|
+
export type UseMutation<TVar, TResponse = any, TError = unknown> = UseStore<MutationState<TVar, TResponse, TError>>;
|
|
26
28
|
export type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = InitStoreOptions<MutationState<TVar, TResponse, TError>> & {
|
|
27
29
|
onMutate?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
28
30
|
onSuccess?: (response: TResponse, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
29
31
|
onError?: (error: TError, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
30
32
|
onSettled?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
31
33
|
};
|
|
32
|
-
export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) =>
|
|
34
|
+
export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => UseMutation<TVar, TResponse, TError>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CreateStoresOptions, StoreKey, UseStores } from './create-stores';
|
|
2
|
-
export type QueryStatus = 'loading' | 'success' | 'error';
|
|
3
2
|
export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = {
|
|
4
3
|
/**
|
|
5
4
|
* Query store key, an object that will be hashed into a string as a query store identifier.
|
|
@@ -44,6 +43,20 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
|
|
|
44
43
|
* Network fetching status for fetching next page.
|
|
45
44
|
*/
|
|
46
45
|
isWaitingNextPage: boolean;
|
|
46
|
+
isRefetching: boolean;
|
|
47
|
+
isRefetchError: boolean;
|
|
48
|
+
isPreviousData: boolean;
|
|
49
|
+
isOptimisticData: boolean;
|
|
50
|
+
error: TError | null;
|
|
51
|
+
errorUpdatedAt: number | null;
|
|
52
|
+
retryCount: number;
|
|
53
|
+
isGoingToRetry: boolean;
|
|
54
|
+
pageParam: any;
|
|
55
|
+
pageParams: any[];
|
|
56
|
+
hasNextPage: boolean;
|
|
57
|
+
retryNextPageCount: number;
|
|
58
|
+
isGoingToRetryNextPage: boolean;
|
|
59
|
+
} & ({
|
|
47
60
|
/**
|
|
48
61
|
* Status of the data.
|
|
49
62
|
*
|
|
@@ -56,39 +69,46 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
|
|
|
56
69
|
* It has no relation with network fetching state.
|
|
57
70
|
* If you're looking for network fetching state, use `isWaiting` instead.
|
|
58
71
|
*/
|
|
59
|
-
status:
|
|
72
|
+
status: 'loading';
|
|
60
73
|
/**
|
|
61
74
|
* Data state, will be `true` if the query has no data.
|
|
62
75
|
*
|
|
63
76
|
* It has no relation with network fetching state.
|
|
64
77
|
* If you're looking for network fetching state, use `isWaiting` instead.
|
|
65
78
|
*/
|
|
66
|
-
isLoading:
|
|
79
|
+
isLoading: true;
|
|
67
80
|
/**
|
|
68
81
|
* Data state, will be `true` if the query has a data.
|
|
69
82
|
*/
|
|
70
|
-
isSuccess:
|
|
71
|
-
/**
|
|
72
|
-
* Error state, will be `true`
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
data:
|
|
80
|
-
response:
|
|
81
|
-
responseUpdatedAt:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
isSuccess: false;
|
|
84
|
+
/**
|
|
85
|
+
* Error state, will be `true` if the query has no data but has an error.
|
|
86
|
+
*
|
|
87
|
+
* This will only happened if an error occured after first fetch.
|
|
88
|
+
*
|
|
89
|
+
* If data fetched successfully but then an error occured, `isError` will be `false` but `isRefetchError` will be `true`.
|
|
90
|
+
*/
|
|
91
|
+
isError: false;
|
|
92
|
+
data: null;
|
|
93
|
+
response: null;
|
|
94
|
+
responseUpdatedAt: null;
|
|
95
|
+
} | {
|
|
96
|
+
status: 'success';
|
|
97
|
+
isLoading: false;
|
|
98
|
+
isSuccess: true;
|
|
99
|
+
isError: false;
|
|
100
|
+
data: TData;
|
|
101
|
+
response: TResponse;
|
|
102
|
+
responseUpdatedAt: number;
|
|
103
|
+
} | {
|
|
104
|
+
status: 'error';
|
|
105
|
+
isLoading: false;
|
|
106
|
+
isSuccess: false;
|
|
107
|
+
isError: true;
|
|
108
|
+
data: null;
|
|
109
|
+
response: null;
|
|
110
|
+
responseUpdatedAt: null;
|
|
111
|
+
});
|
|
92
112
|
export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = CreateStoresOptions<TKey, QueryState<TKey, TResponse, TData, TError>> & {
|
|
93
113
|
select?: (response: TResponse, state: Pick<QueryState<TKey, TResponse, TData, TError>, 'data' | 'key'>) => TData;
|
|
94
114
|
/**
|
|
@@ -116,7 +116,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
116
116
|
const prevState = get();
|
|
117
117
|
const errorUpdatedAt = Date.now();
|
|
118
118
|
const { shouldRetry, delay } = getRetryProps(error, prevState.retryCount);
|
|
119
|
-
set(prevState.isSuccess
|
|
119
|
+
set(prevState.isSuccess && !prevState.isPreviousData
|
|
120
120
|
? {
|
|
121
121
|
isWaiting: false,
|
|
122
122
|
isRefetching: false,
|
|
@@ -136,6 +136,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
136
136
|
isWaiting: false,
|
|
137
137
|
status: 'error',
|
|
138
138
|
isError: true,
|
|
139
|
+
data: null,
|
|
139
140
|
error,
|
|
140
141
|
errorUpdatedAt,
|
|
141
142
|
isGoingToRetry: shouldRetry,
|
|
@@ -254,9 +255,12 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
254
255
|
const prevData = useQuery.get(prevKey);
|
|
255
256
|
if (prevData.data) {
|
|
256
257
|
useQuery.set(nextKey, {
|
|
258
|
+
status: 'success',
|
|
259
|
+
isLoading: false,
|
|
260
|
+
isSuccess: true,
|
|
261
|
+
isError: false,
|
|
257
262
|
data: prevData.data,
|
|
258
263
|
response: prevData.response,
|
|
259
|
-
isLoading: false,
|
|
260
264
|
isPreviousData: true,
|
|
261
265
|
}, true);
|
|
262
266
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InitStoreOptions } from '../vanilla';
|
|
2
|
+
import { UseStore } from './create-store';
|
|
2
3
|
export type MutationState<TVar, TResponse = any, TError = unknown> = {
|
|
3
4
|
/**
|
|
4
5
|
* Network fetching status.
|
|
@@ -23,10 +24,11 @@ export type MutationState<TVar, TResponse = any, TError = unknown> = {
|
|
|
23
24
|
variables?: TVar;
|
|
24
25
|
}>;
|
|
25
26
|
};
|
|
27
|
+
export type UseMutation<TVar, TResponse = any, TError = unknown> = UseStore<MutationState<TVar, TResponse, TError>>;
|
|
26
28
|
export type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = InitStoreOptions<MutationState<TVar, TResponse, TError>> & {
|
|
27
29
|
onMutate?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
28
30
|
onSuccess?: (response: TResponse, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
29
31
|
onError?: (error: TError, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
30
32
|
onSettled?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
31
33
|
};
|
|
32
|
-
export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) =>
|
|
34
|
+
export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => UseMutation<TVar, TResponse, TError>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CreateStoresOptions, StoreKey, UseStores } from './create-stores';
|
|
2
|
-
export type QueryStatus = 'loading' | 'success' | 'error';
|
|
3
2
|
export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = {
|
|
4
3
|
/**
|
|
5
4
|
* Query store key, an object that will be hashed into a string as a query store identifier.
|
|
@@ -44,6 +43,20 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
|
|
|
44
43
|
* Network fetching status for fetching next page.
|
|
45
44
|
*/
|
|
46
45
|
isWaitingNextPage: boolean;
|
|
46
|
+
isRefetching: boolean;
|
|
47
|
+
isRefetchError: boolean;
|
|
48
|
+
isPreviousData: boolean;
|
|
49
|
+
isOptimisticData: boolean;
|
|
50
|
+
error: TError | null;
|
|
51
|
+
errorUpdatedAt: number | null;
|
|
52
|
+
retryCount: number;
|
|
53
|
+
isGoingToRetry: boolean;
|
|
54
|
+
pageParam: any;
|
|
55
|
+
pageParams: any[];
|
|
56
|
+
hasNextPage: boolean;
|
|
57
|
+
retryNextPageCount: number;
|
|
58
|
+
isGoingToRetryNextPage: boolean;
|
|
59
|
+
} & ({
|
|
47
60
|
/**
|
|
48
61
|
* Status of the data.
|
|
49
62
|
*
|
|
@@ -56,39 +69,46 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
|
|
|
56
69
|
* It has no relation with network fetching state.
|
|
57
70
|
* If you're looking for network fetching state, use `isWaiting` instead.
|
|
58
71
|
*/
|
|
59
|
-
status:
|
|
72
|
+
status: 'loading';
|
|
60
73
|
/**
|
|
61
74
|
* Data state, will be `true` if the query has no data.
|
|
62
75
|
*
|
|
63
76
|
* It has no relation with network fetching state.
|
|
64
77
|
* If you're looking for network fetching state, use `isWaiting` instead.
|
|
65
78
|
*/
|
|
66
|
-
isLoading:
|
|
79
|
+
isLoading: true;
|
|
67
80
|
/**
|
|
68
81
|
* Data state, will be `true` if the query has a data.
|
|
69
82
|
*/
|
|
70
|
-
isSuccess:
|
|
71
|
-
/**
|
|
72
|
-
* Error state, will be `true`
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
data:
|
|
80
|
-
response:
|
|
81
|
-
responseUpdatedAt:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
isSuccess: false;
|
|
84
|
+
/**
|
|
85
|
+
* Error state, will be `true` if the query has no data but has an error.
|
|
86
|
+
*
|
|
87
|
+
* This will only happened if an error occured after first fetch.
|
|
88
|
+
*
|
|
89
|
+
* If data fetched successfully but then an error occured, `isError` will be `false` but `isRefetchError` will be `true`.
|
|
90
|
+
*/
|
|
91
|
+
isError: false;
|
|
92
|
+
data: null;
|
|
93
|
+
response: null;
|
|
94
|
+
responseUpdatedAt: null;
|
|
95
|
+
} | {
|
|
96
|
+
status: 'success';
|
|
97
|
+
isLoading: false;
|
|
98
|
+
isSuccess: true;
|
|
99
|
+
isError: false;
|
|
100
|
+
data: TData;
|
|
101
|
+
response: TResponse;
|
|
102
|
+
responseUpdatedAt: number;
|
|
103
|
+
} | {
|
|
104
|
+
status: 'error';
|
|
105
|
+
isLoading: false;
|
|
106
|
+
isSuccess: false;
|
|
107
|
+
isError: true;
|
|
108
|
+
data: null;
|
|
109
|
+
response: null;
|
|
110
|
+
responseUpdatedAt: null;
|
|
111
|
+
});
|
|
92
112
|
export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = CreateStoresOptions<TKey, QueryState<TKey, TResponse, TData, TError>> & {
|
|
93
113
|
select?: (response: TResponse, state: Pick<QueryState<TKey, TResponse, TData, TError>, 'data' | 'key'>) => TData;
|
|
94
114
|
/**
|
|
@@ -116,7 +116,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
116
116
|
const prevState = get();
|
|
117
117
|
const errorUpdatedAt = Date.now();
|
|
118
118
|
const { shouldRetry, delay } = getRetryProps(error, prevState.retryCount);
|
|
119
|
-
set(prevState.isSuccess
|
|
119
|
+
set(prevState.isSuccess && !prevState.isPreviousData
|
|
120
120
|
? {
|
|
121
121
|
isWaiting: false,
|
|
122
122
|
isRefetching: false,
|
|
@@ -136,6 +136,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
136
136
|
isWaiting: false,
|
|
137
137
|
status: 'error',
|
|
138
138
|
isError: true,
|
|
139
|
+
data: null,
|
|
139
140
|
error,
|
|
140
141
|
errorUpdatedAt,
|
|
141
142
|
isGoingToRetry: shouldRetry,
|
|
@@ -254,9 +255,12 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
254
255
|
const prevData = useQuery.get(prevKey);
|
|
255
256
|
if (prevData.data) {
|
|
256
257
|
useQuery.set(nextKey, {
|
|
258
|
+
status: 'success',
|
|
259
|
+
isLoading: false,
|
|
260
|
+
isSuccess: true,
|
|
261
|
+
isError: false,
|
|
257
262
|
data: prevData.data,
|
|
258
263
|
response: prevData.response,
|
|
259
|
-
isLoading: false,
|
|
260
264
|
isPreviousData: true,
|
|
261
265
|
}, true);
|
|
262
266
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InitStoreOptions } from '../vanilla';
|
|
2
|
+
import { UseStore } from './create-store';
|
|
2
3
|
export type MutationState<TVar, TResponse = any, TError = unknown> = {
|
|
3
4
|
/**
|
|
4
5
|
* Network fetching status.
|
|
@@ -23,10 +24,11 @@ export type MutationState<TVar, TResponse = any, TError = unknown> = {
|
|
|
23
24
|
variables?: TVar;
|
|
24
25
|
}>;
|
|
25
26
|
};
|
|
27
|
+
export type UseMutation<TVar, TResponse = any, TError = unknown> = UseStore<MutationState<TVar, TResponse, TError>>;
|
|
26
28
|
export type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = InitStoreOptions<MutationState<TVar, TResponse, TError>> & {
|
|
27
29
|
onMutate?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
28
30
|
onSuccess?: (response: TResponse, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
29
31
|
onError?: (error: TError, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
30
32
|
onSettled?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
31
33
|
};
|
|
32
|
-
export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) =>
|
|
34
|
+
export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => UseMutation<TVar, TResponse, TError>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CreateStoresOptions, StoreKey, UseStores } from './create-stores';
|
|
2
|
-
export type QueryStatus = 'loading' | 'success' | 'error';
|
|
3
2
|
export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = {
|
|
4
3
|
/**
|
|
5
4
|
* Query store key, an object that will be hashed into a string as a query store identifier.
|
|
@@ -44,6 +43,20 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
|
|
|
44
43
|
* Network fetching status for fetching next page.
|
|
45
44
|
*/
|
|
46
45
|
isWaitingNextPage: boolean;
|
|
46
|
+
isRefetching: boolean;
|
|
47
|
+
isRefetchError: boolean;
|
|
48
|
+
isPreviousData: boolean;
|
|
49
|
+
isOptimisticData: boolean;
|
|
50
|
+
error: TError | null;
|
|
51
|
+
errorUpdatedAt: number | null;
|
|
52
|
+
retryCount: number;
|
|
53
|
+
isGoingToRetry: boolean;
|
|
54
|
+
pageParam: any;
|
|
55
|
+
pageParams: any[];
|
|
56
|
+
hasNextPage: boolean;
|
|
57
|
+
retryNextPageCount: number;
|
|
58
|
+
isGoingToRetryNextPage: boolean;
|
|
59
|
+
} & ({
|
|
47
60
|
/**
|
|
48
61
|
* Status of the data.
|
|
49
62
|
*
|
|
@@ -56,39 +69,46 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
|
|
|
56
69
|
* It has no relation with network fetching state.
|
|
57
70
|
* If you're looking for network fetching state, use `isWaiting` instead.
|
|
58
71
|
*/
|
|
59
|
-
status:
|
|
72
|
+
status: 'loading';
|
|
60
73
|
/**
|
|
61
74
|
* Data state, will be `true` if the query has no data.
|
|
62
75
|
*
|
|
63
76
|
* It has no relation with network fetching state.
|
|
64
77
|
* If you're looking for network fetching state, use `isWaiting` instead.
|
|
65
78
|
*/
|
|
66
|
-
isLoading:
|
|
79
|
+
isLoading: true;
|
|
67
80
|
/**
|
|
68
81
|
* Data state, will be `true` if the query has a data.
|
|
69
82
|
*/
|
|
70
|
-
isSuccess:
|
|
71
|
-
/**
|
|
72
|
-
* Error state, will be `true`
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
data:
|
|
80
|
-
response:
|
|
81
|
-
responseUpdatedAt:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
isSuccess: false;
|
|
84
|
+
/**
|
|
85
|
+
* Error state, will be `true` if the query has no data but has an error.
|
|
86
|
+
*
|
|
87
|
+
* This will only happened if an error occured after first fetch.
|
|
88
|
+
*
|
|
89
|
+
* If data fetched successfully but then an error occured, `isError` will be `false` but `isRefetchError` will be `true`.
|
|
90
|
+
*/
|
|
91
|
+
isError: false;
|
|
92
|
+
data: null;
|
|
93
|
+
response: null;
|
|
94
|
+
responseUpdatedAt: null;
|
|
95
|
+
} | {
|
|
96
|
+
status: 'success';
|
|
97
|
+
isLoading: false;
|
|
98
|
+
isSuccess: true;
|
|
99
|
+
isError: false;
|
|
100
|
+
data: TData;
|
|
101
|
+
response: TResponse;
|
|
102
|
+
responseUpdatedAt: number;
|
|
103
|
+
} | {
|
|
104
|
+
status: 'error';
|
|
105
|
+
isLoading: false;
|
|
106
|
+
isSuccess: false;
|
|
107
|
+
isError: true;
|
|
108
|
+
data: null;
|
|
109
|
+
response: null;
|
|
110
|
+
responseUpdatedAt: null;
|
|
111
|
+
});
|
|
92
112
|
export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = CreateStoresOptions<TKey, QueryState<TKey, TResponse, TData, TError>> & {
|
|
93
113
|
select?: (response: TResponse, state: Pick<QueryState<TKey, TResponse, TData, TError>, 'data' | 'key'>) => TData;
|
|
94
114
|
/**
|
|
@@ -119,7 +119,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
119
119
|
const prevState = get();
|
|
120
120
|
const errorUpdatedAt = Date.now();
|
|
121
121
|
const { shouldRetry, delay } = getRetryProps(error, prevState.retryCount);
|
|
122
|
-
set(prevState.isSuccess
|
|
122
|
+
set(prevState.isSuccess && !prevState.isPreviousData
|
|
123
123
|
? {
|
|
124
124
|
isWaiting: false,
|
|
125
125
|
isRefetching: false,
|
|
@@ -139,6 +139,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
139
139
|
isWaiting: false,
|
|
140
140
|
status: 'error',
|
|
141
141
|
isError: true,
|
|
142
|
+
data: null,
|
|
142
143
|
error,
|
|
143
144
|
errorUpdatedAt,
|
|
144
145
|
isGoingToRetry: shouldRetry,
|
|
@@ -257,9 +258,12 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
257
258
|
const prevData = useQuery.get(prevKey);
|
|
258
259
|
if (prevData.data) {
|
|
259
260
|
useQuery.set(nextKey, {
|
|
261
|
+
status: 'success',
|
|
262
|
+
isLoading: false,
|
|
263
|
+
isSuccess: true,
|
|
264
|
+
isError: false,
|
|
260
265
|
data: prevData.data,
|
|
261
266
|
response: prevData.response,
|
|
262
|
-
isLoading: false,
|
|
263
267
|
isPreviousData: true,
|
|
264
268
|
}, true);
|
|
265
269
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InitStoreOptions } from '../vanilla';
|
|
2
|
+
import { UseStore } from './create-store';
|
|
2
3
|
export type MutationState<TVar, TResponse = any, TError = unknown> = {
|
|
3
4
|
/**
|
|
4
5
|
* Network fetching status.
|
|
@@ -23,10 +24,11 @@ export type MutationState<TVar, TResponse = any, TError = unknown> = {
|
|
|
23
24
|
variables?: TVar;
|
|
24
25
|
}>;
|
|
25
26
|
};
|
|
27
|
+
export type UseMutation<TVar, TResponse = any, TError = unknown> = UseStore<MutationState<TVar, TResponse, TError>>;
|
|
26
28
|
export type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = InitStoreOptions<MutationState<TVar, TResponse, TError>> & {
|
|
27
29
|
onMutate?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
28
30
|
onSuccess?: (response: TResponse, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
29
31
|
onError?: (error: TError, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
30
32
|
onSettled?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
31
33
|
};
|
|
32
|
-
export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) =>
|
|
34
|
+
export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => UseMutation<TVar, TResponse, TError>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CreateStoresOptions, StoreKey, UseStores } from './create-stores';
|
|
2
|
-
export type QueryStatus = 'loading' | 'success' | 'error';
|
|
3
2
|
export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = {
|
|
4
3
|
/**
|
|
5
4
|
* Query store key, an object that will be hashed into a string as a query store identifier.
|
|
@@ -44,6 +43,20 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
|
|
|
44
43
|
* Network fetching status for fetching next page.
|
|
45
44
|
*/
|
|
46
45
|
isWaitingNextPage: boolean;
|
|
46
|
+
isRefetching: boolean;
|
|
47
|
+
isRefetchError: boolean;
|
|
48
|
+
isPreviousData: boolean;
|
|
49
|
+
isOptimisticData: boolean;
|
|
50
|
+
error: TError | null;
|
|
51
|
+
errorUpdatedAt: number | null;
|
|
52
|
+
retryCount: number;
|
|
53
|
+
isGoingToRetry: boolean;
|
|
54
|
+
pageParam: any;
|
|
55
|
+
pageParams: any[];
|
|
56
|
+
hasNextPage: boolean;
|
|
57
|
+
retryNextPageCount: number;
|
|
58
|
+
isGoingToRetryNextPage: boolean;
|
|
59
|
+
} & ({
|
|
47
60
|
/**
|
|
48
61
|
* Status of the data.
|
|
49
62
|
*
|
|
@@ -56,39 +69,46 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
|
|
|
56
69
|
* It has no relation with network fetching state.
|
|
57
70
|
* If you're looking for network fetching state, use `isWaiting` instead.
|
|
58
71
|
*/
|
|
59
|
-
status:
|
|
72
|
+
status: 'loading';
|
|
60
73
|
/**
|
|
61
74
|
* Data state, will be `true` if the query has no data.
|
|
62
75
|
*
|
|
63
76
|
* It has no relation with network fetching state.
|
|
64
77
|
* If you're looking for network fetching state, use `isWaiting` instead.
|
|
65
78
|
*/
|
|
66
|
-
isLoading:
|
|
79
|
+
isLoading: true;
|
|
67
80
|
/**
|
|
68
81
|
* Data state, will be `true` if the query has a data.
|
|
69
82
|
*/
|
|
70
|
-
isSuccess:
|
|
71
|
-
/**
|
|
72
|
-
* Error state, will be `true`
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
data:
|
|
80
|
-
response:
|
|
81
|
-
responseUpdatedAt:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
isSuccess: false;
|
|
84
|
+
/**
|
|
85
|
+
* Error state, will be `true` if the query has no data but has an error.
|
|
86
|
+
*
|
|
87
|
+
* This will only happened if an error occured after first fetch.
|
|
88
|
+
*
|
|
89
|
+
* If data fetched successfully but then an error occured, `isError` will be `false` but `isRefetchError` will be `true`.
|
|
90
|
+
*/
|
|
91
|
+
isError: false;
|
|
92
|
+
data: null;
|
|
93
|
+
response: null;
|
|
94
|
+
responseUpdatedAt: null;
|
|
95
|
+
} | {
|
|
96
|
+
status: 'success';
|
|
97
|
+
isLoading: false;
|
|
98
|
+
isSuccess: true;
|
|
99
|
+
isError: false;
|
|
100
|
+
data: TData;
|
|
101
|
+
response: TResponse;
|
|
102
|
+
responseUpdatedAt: number;
|
|
103
|
+
} | {
|
|
104
|
+
status: 'error';
|
|
105
|
+
isLoading: false;
|
|
106
|
+
isSuccess: false;
|
|
107
|
+
isError: true;
|
|
108
|
+
data: null;
|
|
109
|
+
response: null;
|
|
110
|
+
responseUpdatedAt: null;
|
|
111
|
+
});
|
|
92
112
|
export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = CreateStoresOptions<TKey, QueryState<TKey, TResponse, TData, TError>> & {
|
|
93
113
|
select?: (response: TResponse, state: Pick<QueryState<TKey, TResponse, TData, TError>, 'data' | 'key'>) => TData;
|
|
94
114
|
/**
|
|
@@ -119,7 +119,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
119
119
|
const prevState = get();
|
|
120
120
|
const errorUpdatedAt = Date.now();
|
|
121
121
|
const { shouldRetry, delay } = getRetryProps(error, prevState.retryCount);
|
|
122
|
-
set(prevState.isSuccess
|
|
122
|
+
set(prevState.isSuccess && !prevState.isPreviousData
|
|
123
123
|
? {
|
|
124
124
|
isWaiting: false,
|
|
125
125
|
isRefetching: false,
|
|
@@ -139,6 +139,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
139
139
|
isWaiting: false,
|
|
140
140
|
status: 'error',
|
|
141
141
|
isError: true,
|
|
142
|
+
data: null,
|
|
142
143
|
error,
|
|
143
144
|
errorUpdatedAt,
|
|
144
145
|
isGoingToRetry: shouldRetry,
|
|
@@ -257,9 +258,12 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
257
258
|
const prevData = useQuery.get(prevKey);
|
|
258
259
|
if (prevData.data) {
|
|
259
260
|
useQuery.set(nextKey, {
|
|
261
|
+
status: 'success',
|
|
262
|
+
isLoading: false,
|
|
263
|
+
isSuccess: true,
|
|
264
|
+
isError: false,
|
|
260
265
|
data: prevData.data,
|
|
261
266
|
response: prevData.response,
|
|
262
|
-
isLoading: false,
|
|
263
267
|
isPreviousData: true,
|
|
264
268
|
}, true);
|
|
265
269
|
}
|