8
8
*/
9
9
10
10
import EventEmitter from '../events' ;
11
- import {
12
- SESSION_STORAGE_LAST_SELECTION_KEY ,
13
- SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ,
14
- SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
15
- __DEBUG__ ,
16
- } from '../constants' ;
17
- import {
18
- sessionStorageGetItem ,
19
- sessionStorageRemoveItem ,
20
- sessionStorageSetItem ,
21
- } from 'react-devtools-shared/src/storage' ;
11
+ import { SESSION_STORAGE_LAST_SELECTION_KEY , __DEBUG__ } from '../constants' ;
22
12
import setupHighlighter from './views/Highlighter' ;
23
13
import {
24
14
initialize as setupTraceUpdates ,
@@ -36,9 +26,16 @@ import type {
36
26
RendererID ,
37
27
RendererInterface ,
38
28
DevToolsHookSettings ,
29
+ ReloadAndProfileConfigPersistence ,
39
30
} from './types' ;
40
31
import type { ComponentFilter } from 'react-devtools-shared/src/frontend/types' ;
41
32
import { isReactNativeEnvironment } from './utils' ;
33
+ import { defaultReloadAndProfileConfigPersistence } from '../utils' ;
34
+ import {
35
+ sessionStorageGetItem ,
36
+ sessionStorageRemoveItem ,
37
+ sessionStorageSetItem ,
38
+ } from '../storage' ;
42
39
43
40
const debug = ( methodName : string , ...args : Array < string > ) => {
44
41
if ( __DEBUG__ ) {
@@ -159,21 +156,27 @@ export default class Agent extends EventEmitter<{
159
156
_persistedSelection : PersistedSelection | null = null ;
160
157
_persistedSelectionMatch : PathMatch | null = null ;
161
158
_traceUpdatesEnabled : boolean = false ;
159
+ _reloadAndProfileConfigPersistence : ReloadAndProfileConfigPersistence ;
162
160
163
- constructor ( bridge : BackendBridge ) {
161
+ constructor (
162
+ bridge : BackendBridge ,
163
+ reloadAndProfileConfigPersistence ? : ReloadAndProfileConfigPersistence = defaultReloadAndProfileConfigPersistence ,
164
+ ) {
164
165
super ( ) ;
165
166
166
- if (
167
- sessionStorageGetItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ) === 'true'
168
- ) {
167
+ this . _reloadAndProfileConfigPersistence = reloadAndProfileConfigPersistence ;
168
+ const { getReloadAndProfileConfig, setReloadAndProfileConfig} =
169
+ reloadAndProfileConfigPersistence ;
170
+ const reloadAndProfileConfig = getReloadAndProfileConfig ( ) ;
171
+ if ( reloadAndProfileConfig . shouldReloadAndProfile ) {
169
172
this . _recordChangeDescriptions =
170
- sessionStorageGetItem (
171
- SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
172
- ) === 'true' ;
173
+ reloadAndProfileConfig . recordChangeDescriptions ;
173
174
this . _isProfiling = true ;
174
175
175
- sessionStorageRemoveItem ( SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ) ;
176
- sessionStorageRemoveItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ) ;
176
+ setReloadAndProfileConfig ( {
177
+ shouldReloadAndProfile : false ,
178
+ recordChangeDescriptions : false ,
179
+ } ) ;
177
180
}
178
181
179
182
const persistedSelectionString = sessionStorageGetItem (
@@ -671,11 +674,10 @@ export default class Agent extends EventEmitter<{
671
674
672
675
reloadAndProfile : ( recordChangeDescriptions : boolean ) = > void =
673
676
recordChangeDescriptions => {
674
- sessionStorageSetItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY , 'true' ) ;
675
- sessionStorageSetItem (
676
- SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
677
- recordChangeDescriptions ? 'true' : 'false' ,
678
- ) ;
677
+ this . _reloadAndProfileConfigPersistence . setReloadAndProfileConfig ( {
678
+ shouldReloadAndProfile : true ,
679
+ recordChangeDescriptions,
680
+ } ) ;
679
681
680
682
// This code path should only be hit if the shell has explicitly told the Store that it supports profiling.
681
683
// In that case, the shell must also listen for this specific message to know when it needs to reload the app.
0 commit comments