10
10
import EventEmitter from '../events' ;
11
11
import {
12
12
SESSION_STORAGE_LAST_SELECTION_KEY ,
13
- SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ,
14
13
SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
14
+ SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ,
15
15
__DEBUG__ ,
16
16
} from '../constants' ;
17
17
import {
@@ -36,6 +36,8 @@ import type {
36
36
RendererID ,
37
37
RendererInterface ,
38
38
DevToolsHookSettings ,
39
+ ReloadAndProfileConfigSetters ,
40
+ ReloadAndProfileConfig ,
39
41
} from './types' ;
40
42
import type { ComponentFilter } from 'react-devtools-shared/src/frontend/types' ;
41
43
import { isReactNativeEnvironment } from './utils' ;
@@ -159,21 +161,27 @@ export default class Agent extends EventEmitter<{
159
161
_persistedSelection : PersistedSelection | null = null ;
160
162
_persistedSelectionMatch : PathMatch | null = null ;
161
163
_traceUpdatesEnabled : boolean = false ;
164
+ _reloadAndProfileConfigSetters : ReloadAndProfileConfigSetters ;
162
165
163
- constructor ( bridge : BackendBridge ) {
166
+ constructor (
167
+ bridge : BackendBridge ,
168
+ reloadAndProfileConfigSetters ? : ReloadAndProfileConfigSetters = defaultReloadAndProfileConfigSetters ,
169
+ ) {
164
170
super ( ) ;
165
171
166
- if (
167
- sessionStorageGetItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ) === 'true'
168
- ) {
172
+ this . _reloadAndProfileConfigSetters = reloadAndProfileConfigSetters ;
173
+ const { getReloadAndProfileConfig, setReloadAndProfileConfig} =
174
+ reloadAndProfileConfigSetters ;
175
+ const reloadAndProfileConfig = getReloadAndProfileConfig ( ) ;
176
+ if ( reloadAndProfileConfig . shouldReloadAndProfile ) {
169
177
this . _recordChangeDescriptions =
170
- sessionStorageGetItem (
171
- SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
172
- ) === 'true' ;
178
+ reloadAndProfileConfig . recordChangeDescriptions ;
173
179
this . _isProfiling = true ;
174
180
175
- sessionStorageRemoveItem ( SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ) ;
176
- sessionStorageRemoveItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ) ;
181
+ setReloadAndProfileConfig ( {
182
+ shouldReloadAndProfile : false ,
183
+ recordChangeDescriptions : false ,
184
+ } ) ;
177
185
}
178
186
179
187
const persistedSelectionString = sessionStorageGetItem (
@@ -671,11 +679,10 @@ export default class Agent extends EventEmitter<{
671
679
672
680
reloadAndProfile : ( recordChangeDescriptions : boolean ) = > void =
673
681
recordChangeDescriptions => {
674
- sessionStorageSetItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY , 'true' ) ;
675
- sessionStorageSetItem (
676
- SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
677
- recordChangeDescriptions ? 'true' : 'false' ,
678
- ) ;
682
+ this . _reloadAndProfileConfigSetters . setReloadAndProfileConfig ( {
683
+ shouldReloadAndProfile : true ,
684
+ recordChangeDescriptions,
685
+ } ) ;
679
686
680
687
// This code path should only be hit if the shell has explicitly told the Store that it supports profiling.
681
688
// In that case, the shell must also listen for this specific message to know when it needs to reload the app.
@@ -956,3 +963,34 @@ export default class Agent extends EventEmitter<{
956
963
}
957
964
} ;
958
965
}
966
+
967
+ const defaultReloadAndProfileConfigSetters : ReloadAndProfileConfigSetters = {
968
+ setReloadAndProfileConfig ( {
969
+ shouldReloadAndProfile,
970
+ recordChangeDescriptions,
971
+ } ) : void {
972
+ if ( shouldReloadAndProfile != null ) {
973
+ sessionStorageSetItem (
974
+ SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ,
975
+ shouldReloadAndProfile ? 'true' : 'false' ,
976
+ ) ;
977
+ }
978
+ if ( recordChangeDescriptions != null ) {
979
+ sessionStorageSetItem (
980
+ SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
981
+ recordChangeDescriptions ? 'true' : 'false' ,
982
+ ) ;
983
+ }
984
+ } ,
985
+ getReloadAndProfileConfig ( ) : ReloadAndProfileConfig {
986
+ return {
987
+ shouldReloadAndProfile :
988
+ sessionStorageGetItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ) ===
989
+ 'true' ,
990
+ recordChangeDescriptions :
991
+ sessionStorageGetItem (
992
+ SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
993
+ ) === 'true' ,
994
+ } ;
995
+ } ,
996
+ } ;
0 commit comments