Skip to content

Commit

Permalink
Fusebox reload-to-profile refactor
Browse files Browse the repository at this point in the history
Summary:
Changelog: [internal]

Follow up on feedback from D64077813

 oliver_clean

Differential Revision: D64469842
  • Loading branch information
EdmondChuiHW authored and facebook-github-bot committed Oct 16, 2024
1 parent 6b67772 commit d74eeff
Showing 1 changed file with 49 additions and 58 deletions.
107 changes: 49 additions & 58 deletions packages/react-native/Libraries/Core/setUpReactDevTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,16 @@ if (__DEV__) {
}
}

const reloadAndProfileConfigPersistence =
makeReloadAndProfileConfigPersistence(
maybeReactDevToolsRuntimeSettingsModuleModule,
);
const {
isReloadAndProfileSupported,
isProfiling,
profilingSettings,
onReloadAndProfile,
onReloadAndProfileFlagsReset,
} = readReloadAndProfileConfig(maybeReactDevToolsRuntimeSettingsModuleModule);

const shouldStartProfilingNow =
reloadAndProfileConfigPersistence?.getReloadAndProfileConfig()
?.shouldReloadAndProfile === true;
const profilingSettings = {
recordChangeDescriptions:
reloadAndProfileConfigPersistence?.getReloadAndProfileConfig()
?.recordChangeDescriptions === true,
recordTimeline: false,
};
// Install hook before React is loaded.
initialize(hookSettings, shouldStartProfilingNow, profilingSettings);
initialize(hookSettings, isProfiling, profilingSettings);

// This should be defined in DEV, otherwise error is expected.
const fuseboxReactDevToolsDispatcher =
Expand Down Expand Up @@ -97,23 +91,10 @@ if (__DEV__) {
nativeStyleEditorValidAttributes: Object.keys(ReactNativeStyleAttributes),
resolveRNStyle,
onSettingsUpdated: handleReactDevToolsSettingsUpdate,
isReloadAndProfileSupported:
maybeReactDevToolsRuntimeSettingsModuleModule != null,
isProfiling:
reloadAndProfileConfigPersistence?.getReloadAndProfileConfig()
?.shouldReloadAndProfile === true,
onReloadAndProfile: (recordChangeDescriptions: boolean) => {
reloadAndProfileConfigPersistence?.setReloadAndProfileConfig({
shouldReloadAndProfile: true,
recordChangeDescriptions,
});
},
onReloadAndProfileFlagsReset: () => {
reloadAndProfileConfigPersistence?.setReloadAndProfileConfig({
shouldReloadAndProfile: false,
recordChangeDescriptions: false,
});
},
isReloadAndProfileSupported,
isProfiling,
onReloadAndProfile,
onReloadAndProfileFlagsReset,
});
}

Expand Down Expand Up @@ -173,23 +154,10 @@ if (__DEV__) {
),
websocket: ws,
onSettingsUpdated: handleReactDevToolsSettingsUpdate,
isReloadAndProfileSupported:
maybeReactDevToolsRuntimeSettingsModuleModule != null,
isProfiling:
reloadAndProfileConfigPersistence?.getReloadAndProfileConfig()
?.shouldReloadAndProfile === true,
onReloadAndProfile: (recordChangeDescriptions: boolean) => {
reloadAndProfileConfigPersistence?.setReloadAndProfileConfig({
shouldReloadAndProfile: true,
recordChangeDescriptions,
});
},
onReloadAndProfileFlagsReset: () => {
reloadAndProfileConfigPersistence?.setReloadAndProfileConfig({
shouldReloadAndProfile: false,
recordChangeDescriptions: false,
});
},
isReloadAndProfileSupported,
isProfiling,
onReloadAndProfile,
onReloadAndProfileFlagsReset,
});
}
}
Expand Down Expand Up @@ -222,19 +190,42 @@ if (__DEV__) {
connectToWSBasedReactDevToolsFrontend(); // Try connecting once on load
}

function makeReloadAndProfileConfigPersistence(
function readReloadAndProfileConfig(
maybeModule: ?NativeReactDevToolsRuntimeSettingsModuleSpec,
) {
if (maybeModule == null) {
return;
}
const isReloadAndProfileSupported = maybeModule != null;
const config = maybeModule?.getReloadAndProfileConfig();
const isProfiling = config?.shouldReloadAndProfile === true;
const profilingSettings = {
recordChangeDescriptions: config?.recordChangeDescriptions === true,
recordTimeline: false,
};
const onReloadAndProfile = (recordChangeDescriptions: boolean) => {
if (maybeModule == null) {
return;
}

maybeModule.setReloadAndProfileConfig({
shouldReloadAndProfile: true,
recordChangeDescriptions,
});
};
const onReloadAndProfileFlagsReset = () => {
if (maybeModule == null) {
return;
}

maybeModule.setReloadAndProfileConfig({
shouldReloadAndProfile: false,
recordChangeDescriptions: false,
});
};

return {
setReloadAndProfileConfig(config: PartialReloadAndProfileConfig): void {
maybeModule.setReloadAndProfileConfig(config);
},
getReloadAndProfileConfig() {
return maybeModule.getReloadAndProfileConfig();
},
isReloadAndProfileSupported,
isProfiling,
profilingSettings,
onReloadAndProfile,
onReloadAndProfileFlagsReset,
};
}

0 comments on commit d74eeff

Please sign in to comment.