1- // @flow
2-
3- // #region flow types
1+ // #region types
42export type DevToolsMessageType = 'DISPATCH' | string ;
53
64export type DevToolsMessagePayload = {
7- type ?: string ,
8- state ?: any ,
9- ...any ,
5+ type ?: string ;
6+ state ?: any ;
107} ;
118
129export type DevToolsMessage = {
13- type ?: DevToolsMessageType ,
14- payload ?: DevToolsMessagePayload ,
15- ...any ,
10+ type ?: DevToolsMessageType ;
11+ payload ?: DevToolsMessagePayload ;
1612} ;
1713
1814export 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 ;
2621} ;
2722// #endregion
2823
2924// #region constants
3025const isDEV = process . env . NODE_ENV === 'development' ;
3126
3227export const withDevTools =
33- isDEV && typeof window !== 'undefined' && window . __REDUX_DEVTOOLS_EXTENSION__ ;
28+ isDEV &&
29+ typeof window !== 'undefined' &&
30+ ( window as any ) . __REDUX_DEVTOOLS_EXTENSION__ ;
3431
35- // $FlowIgnore
3632const devTools : DevTools = ! withDevTools
3733 ? null
38- : window . __REDUX_DEVTOOLS_EXTENSION__ . connect ( ) ;
34+ : ( window as any ) . __REDUX_DEVTOOLS_EXTENSION__ . connect ( ) ;
3935// #endregion
4036
4137// #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 = {
4347 auth : { } ,
4448} ;
4549
46- export const reducer = (
47- state : any = initialState ,
48- action : { type : string , ...any } ,
49- ) => {
50+ export const reducer = ( state : State = initialState , action : Action ) => {
5051 /* eslint-disable no-unused-vars */
5152 switch ( action . type ) {
5253 // #region auth context
@@ -68,7 +69,7 @@ export const reducer = (
6869// #endregion
6970
7071// #region singleton devtools local state
71- let state ;
72+ let state : State ;
7273// #endregion
7374
7475// #region devToolsStore (redux like)
@@ -77,7 +78,7 @@ export const devToolsStore = !withDevTools
7778 ? null
7879 : {
7980 ...devTools ,
80- dispatch : action => {
81+ dispatch : ( action : Action ) => {
8182 // #region action validation
8283 if ( ! action ) {
8384 throw new Error ( 'devTools dispatched action should be defined' ) ;
0 commit comments