@@ -10,7 +10,7 @@ const monitorActions = [
1010] ;
1111
1212window . devToolsExtension = function ( config = { } ) {
13- let store = { } ;
13+ let liftedStore ;
1414 if ( ! window . devToolsOptions ) window . devToolsOptions = { } ;
1515
1616 let localFilter ;
@@ -78,12 +78,12 @@ window.devToolsExtension = function(config = {}) {
7878 }
7979
8080 if ( message . type === 'DISPATCH' ) {
81- store . liftedStore . dispatch ( message . payload ) ;
81+ liftedStore . dispatch ( message . payload ) ;
8282 } else if ( message . type === 'UPDATE' ) {
83- relay ( 'STATE' , store . liftedStore . getState ( ) ) ;
83+ relay ( 'STATE' , liftedStore . getState ( ) ) ;
8484 } else if ( message . type === 'START' ) {
8585 isMonitored = true ;
86- relay ( 'STATE' , store . liftedStore . getState ( ) ) ;
86+ relay ( 'STATE' , liftedStore . getState ( ) ) ;
8787 } else if ( message . type === 'STOP' ) {
8888 isMonitored = false ;
8989 }
@@ -119,7 +119,7 @@ window.devToolsExtension = function(config = {}) {
119119 relay ( 'INIT_INSTANCE' ) ;
120120 notifyErrors ( ( ) => {
121121 errorOccurred = true ;
122- const state = store . liftedStore . getState ( ) ;
122+ const state = liftedStore . getState ( ) ;
123123 if ( state . computedStates [ state . currentStateIndex ] . error ) {
124124 relay ( 'STATE' , state ) ;
125125 return false ;
@@ -130,18 +130,18 @@ window.devToolsExtension = function(config = {}) {
130130 // Detect when the tab is reactivated
131131 document . addEventListener ( 'visibilitychange' , function ( ) {
132132 if ( document . visibilityState === 'visible' && isMonitored ) {
133- relay ( 'STATE' , store . liftedStore . getState ( ) ) ;
133+ relay ( 'STATE' , liftedStore . getState ( ) ) ;
134134 }
135135 } , false ) ;
136136 }
137137
138138 function monitorReducer ( state = { } , action ) {
139139 if ( ! isMonitored ) return state ;
140140 lastAction = action . type ;
141- if ( lastAction === '@@redux/INIT' && store . liftedStore ) {
141+ if ( lastAction === '@@redux/INIT' && liftedStore ) {
142142 // Send new lifted state on hot-reloading
143143 setTimeout ( ( ) => {
144- relay ( 'STATE' , store . liftedStore . getState ( ) ) ;
144+ relay ( 'STATE' , liftedStore . getState ( ) ) ;
145145 } , 0 ) ;
146146 }
147147 return logMonitorReducer ( { } , state , action ) ;
@@ -165,20 +165,24 @@ window.devToolsExtension = function(config = {}) {
165165 }
166166 }
167167
168- return ( next ) => {
168+ function extEnhancer ( next ) {
169169 return ( reducer , initialState , enhancer ) => {
170- if ( ! isAllowed ( window . devToolsOptions ) ) return next ( reducer , initialState , enhancer ) ;
171-
172- const { deserializeState, deserializeAction } = config ;
173- store = configureStore ( next , monitorReducer , {
174- deserializeState,
175- deserializeAction
176- } ) ( reducer , initialState , enhancer ) ;
177170 init ( ) ;
178- store . subscribe ( ( ) => { handleChange ( store . getState ( ) , store . liftedStore . getState ( ) ) ; } ) ;
171+ const store = next ( reducer , initialState , enhancer ) ;
172+ liftedStore = store . liftedStore ;
173+ store . subscribe ( ( ) => {
174+ handleChange ( store . getState ( ) , liftedStore . getState ( ) ) ;
175+ } ) ;
179176 return store ;
180177 } ;
181- } ;
178+ }
179+
180+ if ( ! isAllowed ( window . devToolsOptions ) ) return f => f ;
181+ const { deserializeState, deserializeAction } = config ;
182+ return configureStore ( extEnhancer , monitorReducer , {
183+ deserializeState,
184+ deserializeAction
185+ } ) ;
182186} ;
183187
184188window . devToolsExtension . open = function ( position ) {
0 commit comments