@@ -22,26 +22,28 @@ const useContextDevTools = (dispatch: Function) => {
2222 // other options like actionSanitizer, stateSanitizer
2323 } ) ;
2424 isInitialized = true ;
25- devTools . current . subscribe ( ( message : any ) => {
26- if ( message . payload && ( message . payload . type === 'JUMP_TO_STATE' || message . payload . type === 'JUMP_TO_ACTION' ) && message . state ) {
27- const parsedState = JSON . parse ( message . state ) ;
28- sendDispatch ( {
29- type : 'IMPORT_STATE' ,
30- state : parsedState ,
31- } ) ;
32- } else if ( message . type === 'DISPATCH' && message . payload && message . payload . nextLiftedState ) {
33- message . payload . nextLiftedState . computedStates . forEach ( ( cs : { state : any } , csi : number ) => {
34- const actionToSend = message . payload . nextLiftedState . actionsById [ csi ] ;
35- if ( actionToSend . action . type !== '@@INIT' ) {
36- sendDispatch ( actionToSend . action ) ;
37- }
38- } ) ;
39- }
40- } ) ;
41- window . addEventListener ( 'beforeunload' , function ( e ) {
42- e . preventDefault ( ) ;
43- disconnectDevTools ( ) ;
44- } ) ;
25+ if ( typeof devTools . current . subscribe === 'function' ) {
26+ devTools . current . subscribe ( ( message : any ) => {
27+ if ( message . payload && ( message . payload . type === 'JUMP_TO_STATE' || message . payload . type === 'JUMP_TO_ACTION' ) && message . state ) {
28+ const parsedState = JSON . parse ( message . state ) ;
29+ sendDispatch ( {
30+ type : 'IMPORT_STATE' ,
31+ state : parsedState ,
32+ } ) ;
33+ } else if ( message . type === 'DISPATCH' && message . payload && message . payload . nextLiftedState ) {
34+ message . payload . nextLiftedState . computedStates . forEach ( ( cs : { state : any } , csi : number ) => {
35+ const actionToSend = message . payload . nextLiftedState . actionsById [ csi ] ;
36+ if ( actionToSend . action . type !== '@@INIT' ) {
37+ sendDispatch ( actionToSend . action ) ;
38+ }
39+ } ) ;
40+ }
41+ } ) ;
42+ window . addEventListener ( 'beforeunload' , function ( e ) {
43+ e . preventDefault ( ) ;
44+ disconnectDevTools ( ) ;
45+ } ) ;
46+ }
4547 }
4648
4749 const sendDispatch = ( args : any ) => {
0 commit comments