1
- // @flow
2
-
3
- // #region flow types
1
+ // #region types
4
2
export type DevToolsMessageType = 'DISPATCH' | string ;
5
3
6
4
export type DevToolsMessagePayload = {
7
- type ?: string ,
8
- state ?: any ,
9
- ...any ,
5
+ type ?: string ;
6
+ state ?: any ;
10
7
} ;
11
8
12
9
export type DevToolsMessage = {
13
- type ?: DevToolsMessageType ,
14
- payload ?: DevToolsMessagePayload ,
15
- ...any ,
10
+ type ?: DevToolsMessageType ;
11
+ payload ?: DevToolsMessagePayload ;
16
12
} ;
17
13
18
14
export type DevTools = {
19
- connect : ( ) => any ,
20
- subscribe : ( message : DevToolsMessage ) => any ,
21
- send : ( type : string , state : any ) => any ,
22
- unsubscribe : ( ) => any ,
23
- dispatch : ( action : { type : string , ...any } ) => any ,
24
- disconnect : ( ) => any ,
25
- ...any ,
15
+ connect : ( ) => any ;
16
+ subscribe : ( message : DevToolsMessage ) => any ;
17
+ send : ( action : { type : string ; state ?: any } , newState : any ) => any ;
18
+ unsubscribe : ( ) => any ;
19
+ dispatch : ( action : { type : string } ) => any ;
20
+ disconnect : ( ) => any ;
26
21
} ;
27
22
// #endregion
28
23
29
24
// #region constants
30
25
const isDEV = process . env . NODE_ENV === 'development' ;
31
26
32
27
export const withDevTools =
33
- isDEV && typeof window !== 'undefined' && window . __REDUX_DEVTOOLS_EXTENSION__ ;
28
+ isDEV &&
29
+ typeof window !== 'undefined' &&
30
+ ( window as any ) . __REDUX_DEVTOOLS_EXTENSION__ ;
34
31
35
- // $FlowIgnore
36
32
const devTools : DevTools = ! withDevTools
37
33
? null
38
- : window . __REDUX_DEVTOOLS_EXTENSION__ . connect ( ) ;
34
+ : ( window as any ) . __REDUX_DEVTOOLS_EXTENSION__ . connect ( ) ;
39
35
// #endregion
40
36
41
37
// #region devtools reducer
42
- const initialState = {
38
+ type State = {
39
+ auth : any ;
40
+ } ;
41
+ type Action = {
42
+ type : string ;
43
+ state ?: any ;
44
+ } ;
45
+
46
+ const initialState : State = {
43
47
auth : { } ,
44
48
} ;
45
49
46
- export const reducer = (
47
- state : any = initialState ,
48
- action : { type : string , ...any } ,
49
- ) => {
50
+ export const reducer = ( state : State = initialState , action : Action ) => {
50
51
/* eslint-disable no-unused-vars */
51
52
switch ( action . type ) {
52
53
// #region auth context
@@ -68,7 +69,7 @@ export const reducer = (
68
69
// #endregion
69
70
70
71
// #region singleton devtools local state
71
- let state ;
72
+ let state : State ;
72
73
// #endregion
73
74
74
75
// #region devToolsStore (redux like)
@@ -77,7 +78,7 @@ export const devToolsStore = !withDevTools
77
78
? null
78
79
: {
79
80
...devTools ,
80
- dispatch : action => {
81
+ dispatch : ( action : Action ) => {
81
82
// #region action validation
82
83
if ( ! action ) {
83
84
throw new Error ( 'devTools dispatched action should be defined' ) ;
0 commit comments