Skip to content

Commit

Permalink
Cleaned up event names
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Oct 2, 2019
1 parent 5b69234 commit e68a3c9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
28 changes: 14 additions & 14 deletions packages/react-devtools-shared/src/backend/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default class Agent extends EventEmitter<{|

this._bridge = bridge;

bridge.addListener('enableTraceUpdates', this.enableTraceUpdates);
bridge.addListener('getProfilingData', this.getProfilingData);
bridge.addListener('getProfilingStatus', this.getProfilingStatus);
bridge.addListener('getOwnersList', this.getOwnersList);
Expand All @@ -149,7 +150,6 @@ export default class Agent extends EventEmitter<{|
this.updateAppendComponentStack,
);
bridge.addListener('updateComponentFilters', this.updateComponentFilters);
bridge.addListener('updateTraceUpdates', this.updateTraceUpdates);
bridge.addListener('viewElementSource', this.viewElementSource);

if (this._isProfiling) {
Expand Down Expand Up @@ -204,6 +204,19 @@ export default class Agent extends EventEmitter<{|
return null;
}

enableTraceUpdates = (isEnabled: boolean) => {
this._traceUpdatesEnabled = isEnabled;

toggleTraceUpdatesEnabled(isEnabled);

for (let rendererID in this._rendererInterfaces) {
const renderer = ((this._rendererInterfaces[
(rendererID: any)
]: any): RendererInterface);
renderer.toggleTraceUpdatesEnabled(isEnabled);
}
};

getProfilingData = ({rendererID}: {|rendererID: RendererID|}) => {
const renderer = this._rendererInterfaces[rendererID];
if (renderer == null) {
Expand Down Expand Up @@ -417,19 +430,6 @@ export default class Agent extends EventEmitter<{|
}
};

updateTraceUpdates = (isEnabled: boolean) => {
this._traceUpdatesEnabled = isEnabled;

toggleTraceUpdatesEnabled(isEnabled);

for (let rendererID in this._rendererInterfaces) {
const renderer = ((this._rendererInterfaces[
(rendererID: any)
]: any): RendererInterface);
renderer.toggleTraceUpdatesEnabled(isEnabled);
}
};

viewElementSource = ({id, rendererID}: ElementAndRendererID) => {
const renderer = this._rendererInterfaces[rendererID];
if (renderer == null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type BackendEvents = {|

type FrontendEvents = {|
clearNativeElementHighlight: [],
enableTraceUpdates: [boolean],
getOwnersList: [ElementAndRendererID],
getProfilingData: [{|rendererID: RendererID|}],
getProfilingStatus: [],
Expand All @@ -115,7 +116,6 @@ type FrontendEvents = {|
stopProfiling: [],
updateAppendComponentStack: [boolean],
updateComponentFilters: [Array<ComponentFilter>],
updateTraceUpdates: [boolean],
viewElementSource: [ElementAndRendererID],

// React Native style editor plug-in.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export default function GeneralSettings(_: {||}) {
const {
appendComponentStack,
displayDensity,
traceUpdates,
setAppendComponentStack,
setTraceUpdates,
setDisplayDensity,
setTheme,
setTraceUpdatesEnabled,
theme,
traceUpdatesEnabled,
} = useContext(SettingsContext);

const {supportsTraceUpdates} = useContext(StoreContext);
Expand Down Expand Up @@ -60,9 +60,9 @@ export default function GeneralSettings(_: {||}) {
<label>
<input
type="checkbox"
checked={traceUpdates}
checked={traceUpdatesEnabled}
onChange={({currentTarget}) =>
setTraceUpdates(currentTarget.checked)
setTraceUpdatesEnabled(currentTarget.checked)
}
/>{' '}
Highlight updates when components render.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type Context = {|
theme: Theme,
setTheme(value: Theme): void,

traceUpdates: boolean,
setTraceUpdates: (value: boolean) => void,
traceUpdatesEnabled: boolean,
setTraceUpdatesEnabled: (value: boolean) => void,
|};

const SettingsContext = createContext<Context>(((null: any): Context));
Expand Down Expand Up @@ -76,10 +76,9 @@ function SettingsContextController({
const [appendComponentStack, setAppendComponentStack] = useLocalStorage<
boolean,
>(LOCAL_STORAGE_SHOULD_PATCH_CONSOLE_KEY, true);
const [traceUpdates, setTraceUpdates] = useLocalStorage<boolean>(
'React::DevTools::traceUpdates',
false,
);
const [traceUpdatesEnabled, setTraceUpdatesEnabled] = useLocalStorage<
boolean,
>('React::DevTools::traceUpdatesEnabled', false);

const documentElements = useMemo<DocumentElements>(
() => {
Expand Down Expand Up @@ -147,35 +146,35 @@ function SettingsContextController({

useEffect(
() => {
bridge.send('updateTraceUpdates', traceUpdates);
bridge.send('enableTraceUpdates', traceUpdatesEnabled);
},
[bridge, traceUpdates],
[bridge, traceUpdatesEnabled],
);

const value = useMemo(
() => ({
displayDensity,
setDisplayDensity,
theme,
setTheme,
appendComponentStack,
setAppendComponentStack,
traceUpdates,
setTraceUpdates,
displayDensity,
lineHeight:
displayDensity === 'compact'
? COMPACT_LINE_HEIGHT
: COMFORTABLE_LINE_HEIGHT,
setAppendComponentStack,
setDisplayDensity,
setTheme,
setTraceUpdatesEnabled,
theme,
traceUpdatesEnabled,
}),
[
appendComponentStack,
displayDensity,
setAppendComponentStack,
setDisplayDensity,
setTheme,
appendComponentStack,
setAppendComponentStack,
traceUpdates,
setTraceUpdates,
setTraceUpdatesEnabled,
theme,
traceUpdatesEnabled,
],
);

Expand Down

0 comments on commit e68a3c9

Please sign in to comment.