File tree Expand file tree Collapse file tree 5 files changed +34
-14
lines changed
redux-query-react/flow-test/hooks Expand file tree Collapse file tree 5 files changed +34
-14
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ import useRequest from '../../src/hooks/use-request';
7
7
const Card = ( ) => {
8
8
const [ { isPending } ] = useRequest ( {
9
9
url : '/api' ,
10
+ customQueryMiddlewareConfig : {
11
+ retryableStatusCodes : [ 504 ] ,
12
+ } ,
10
13
} ) ;
11
14
12
15
return < div > { isPending ? 'loading…' : 'loaded' } </ div > ;
Original file line number Diff line number Diff line change @@ -39,15 +39,15 @@ declare module 'redux-query' {
39
39
export type RollbackStrategy < T > = ( initialValue : T , currentValue : T ) => T ;
40
40
41
41
export type Update < TEntities = Entities > = {
42
- [ K in keyof TEntities ] ?: UpdateStrategy < TEntities [ K ] >
42
+ [ K in keyof TEntities ] ?: UpdateStrategy < TEntities [ K ] > ;
43
43
} ;
44
44
45
45
export type OptimisticUpdate < TEntities = Entities > = {
46
- [ K in keyof TEntities ] ?: OptimisticUpdateStrategy < TEntities [ K ] >
46
+ [ K in keyof TEntities ] ?: OptimisticUpdateStrategy < TEntities [ K ] > ;
47
47
} ;
48
48
49
49
export type Rollback < TEntities = Entities > = {
50
- [ K in keyof TEntities ] ?: RollbackStrategy < TEntities [ K ] >
50
+ [ K in keyof TEntities ] ?: RollbackStrategy < TEntities [ K ] > ;
51
51
} ;
52
52
53
53
export interface WithTime {
@@ -158,6 +158,15 @@ declare module 'redux-query' {
158
158
queryCount : number ;
159
159
} ;
160
160
161
+ export type QueryMiddlewareConfig = {
162
+ backoff : {
163
+ maxAttempts : number ;
164
+ minDuration : number ;
165
+ maxDuration : number ;
166
+ } ;
167
+ retryableStatusCodes : Array < Status > ;
168
+ } ;
169
+
161
170
export interface QueryConfig < TEntities = Entities > {
162
171
body ?: RequestBody ;
163
172
force ?: boolean ;
@@ -171,6 +180,7 @@ declare module 'redux-query' {
171
180
rollback ?: Rollback < TEntities > ;
172
181
unstable_preDispatchCallback ?: ( ) => void ;
173
182
url : Url ;
183
+ customQueryMiddlewareConfig ?: QueryMiddlewareConfig ;
174
184
}
175
185
176
186
export interface QueriesState {
Original file line number Diff line number Diff line change @@ -276,6 +276,7 @@ export const requestAsync = ({
276
276
url,
277
277
/* eslint-disable-next-line camelcase */
278
278
unstable_preDispatchCallback,
279
+ customQueryMiddlewareConfig,
279
280
} : QueryConfig ) : RequestAsyncAction => {
280
281
return {
281
282
type : actionTypes . REQUEST_ASYNC ,
@@ -289,6 +290,7 @@ export const requestAsync = ({
289
290
update,
290
291
url,
291
292
unstable_preDispatchCallback,
293
+ customQueryMiddlewareConfig,
292
294
} ;
293
295
} ;
294
296
@@ -307,6 +309,7 @@ export const mutateAsync = ({
307
309
transform,
308
310
update,
309
311
url,
312
+ customQueryMiddlewareConfig,
310
313
} : QueryConfig ) : MutateAsyncAction => {
311
314
return {
312
315
type : actionTypes . MUTATE_ASYNC ,
@@ -319,6 +322,7 @@ export const mutateAsync = ({
319
322
transform,
320
323
update,
321
324
url,
325
+ customQueryMiddlewareConfig,
322
326
} ;
323
327
} ;
324
328
Original file line number Diff line number Diff line change @@ -29,25 +29,17 @@ import type {
29
29
ResponseBody ,
30
30
Status ,
31
31
Transform ,
32
+ QueryMiddlewareConfig ,
32
33
} from '../types' ;
33
34
34
- type Config = { |
35
- backoff : { |
36
- maxAttempts : number ,
37
- minDuration : number ,
38
- maxDuration : number ,
39
- | } ,
40
- retryableStatusCodes : Array < Status > ,
41
- | } ;
42
-
43
35
type ReduxStore = { |
44
36
dispatch : ( action : Action ) => any ,
45
37
getState : ( ) => any ,
46
38
| } ;
47
39
48
40
type Next = ( action : PublicAction ) => any ;
49
41
50
- const defaultConfig : Config = {
42
+ const defaultConfig : QueryMiddlewareConfig = {
51
43
backoff : {
52
44
maxAttempts : 5 ,
53
45
minDuration : 300 ,
@@ -105,7 +97,8 @@ const queryMiddleware = (
105
97
106
98
return ( { dispatch, getState } : ReduxStore ) => ( next : Next ) => ( action : PublicAction ) => {
107
99
let returnValue ;
108
- const config = { ...defaultConfig , ...customConfig } ;
100
+ const customQueryMiddlewareConfigFromAction = action . customQueryMiddlewareConfig || { } ;
101
+ const config = { ...defaultConfig , ...customConfig , ...customQueryMiddlewareConfigFromAction } ;
109
102
110
103
switch ( action . type ) {
111
104
case actionTypes . REQUEST_ASYNC : {
Original file line number Diff line number Diff line change @@ -13,6 +13,15 @@ type QueryOptions = {
13
13
headers ?: { [ key : string ] : any } ,
14
14
} ;
15
15
16
+ export type QueryMiddlewareConfig = { |
17
+ backoff : { |
18
+ maxAttempts : number ,
19
+ minDuration : number ,
20
+ maxDuration : number ,
21
+ | } ,
22
+ retryableStatusCodes : Array < Status > ,
23
+ | } ;
24
+
16
25
export type QueryConfig = { |
17
26
body ? : RequestBody ,
18
27
force ? : boolean ,
@@ -26,6 +35,7 @@ export type QueryConfig = {|
26
35
rollback ?: { [ key : string ] : ( initialValue : any , currentValue : any ) => any } ,
27
36
unstable_preDispatchCallback ?: ( ) => void ,
28
37
url : Url ,
38
+ customQueryMiddlewareConfig ? : QueryMiddlewareConfig ,
29
39
| } ;
30
40
31
41
export type QueryDetails = {
You can’t perform that action at this time.
0 commit comments