Skip to content

Commit 9fe74f2

Browse files
authored
Set the preview selection to null when there is no selection (#5568)
We are currently using a "no preview selection" object of the shape `{ hasSelection: false, isModifying: false }` when there is no preview selection. We can instead just use null, it's more idiomatic. I recommend reviewing commits individually.
2 parents 45ef09c + 118c6a4 commit 9fe74f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+138
-213
lines changed

src/actions/profile-view.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,13 +1749,17 @@ export function changeShowJsTracerSummary(
17491749
}
17501750

17511751
export function updatePreviewSelection(
1752-
previewSelection: PreviewSelection
1752+
previewSelection: PreviewSelection | null
17531753
): ThunkAction<void> {
17541754
return (dispatch, getState) => {
1755+
// Only dispatch if the selection changes. This function can fire in a tight loop,
1756+
// and this check saves a dispatch.
17551757
const currentPreviewSelection = getPreviewSelection(getState());
1756-
if (!objectShallowEquals(currentPreviewSelection, previewSelection)) {
1757-
// Only dispatch if the selection changes. This function can fire in a tight loop,
1758-
// and this check saves a dispatch.
1758+
if (
1759+
!currentPreviewSelection ||
1760+
!previewSelection ||
1761+
!objectShallowEquals(currentPreviewSelection, previewSelection)
1762+
) {
17591763
dispatch({
17601764
type: 'UPDATE_PREVIEW_SELECTION',
17611765
previewSelection,

src/components/app/BottomBox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
getSourceViewCode,
2929
getAssemblyViewCode,
3030
} from 'firefox-profiler/selectors/code';
31-
import { getPreviewSelection } from 'firefox-profiler/selectors/profile';
31+
import { getPreviewSelectionIsBeingModified } from 'firefox-profiler/selectors/profile';
3232
import explicitConnect from 'firefox-profiler/utils/connect';
3333

3434
import type { ConnectedProps } from 'firefox-profiler/utils/connect';
@@ -295,7 +295,7 @@ export const BottomBox = explicitConnect<{}, StateProps, DispatchProps>({
295295
selectedNodeSelectors.getAssemblyViewAddressTimings(state),
296296
assemblyViewScrollGeneration: getAssemblyViewScrollGeneration(state),
297297
assemblyViewIsOpen: getAssemblyViewIsOpen(state),
298-
disableOverscan: getPreviewSelection(state).isModifying,
298+
disableOverscan: getPreviewSelectionIsBeingModified(state),
299299
}),
300300
mapDispatchToProps: {
301301
closeBottomBox,

src/components/app/ProfileFilterNavigator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export const ProfileFilterNavigator = explicitConnect<
187187
const items = getCommittedRangeLabels(state);
188188
const previewSelection = getPreviewSelection(state);
189189
const profileTimelineUnit = getProfileTimelineUnit(state);
190-
const uncommittedItem = previewSelection.hasSelection
190+
const uncommittedItem = previewSelection
191191
? getFormattedTimelineValue(
192192
previewSelection.selectionEnd - previewSelection.selectionStart,
193193
profileTimelineUnit

src/components/calltree/CallTree.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import {
1717
getScrollToSelectionGeneration,
1818
getFocusCallTreeGeneration,
19-
getPreviewSelection,
19+
getPreviewSelectionIsBeingModified,
2020
getCategories,
2121
getCurrentTableViewOptions,
2222
} from 'firefox-profiler/selectors/profile';
@@ -410,7 +410,7 @@ export const CallTree = explicitConnect<{}, StateProps, DispatchProps>({
410410
expandedCallNodeIndexes:
411411
selectedThreadSelectors.getExpandedCallNodeIndexes(state),
412412
searchStringsRegExp: getSearchStringsAsRegExp(state),
413-
disableOverscan: getPreviewSelection(state).isModifying,
413+
disableOverscan: getPreviewSelectionIsBeingModified(state),
414414
invertCallstack: getInvertCallstack(state),
415415
implementationFilter: getImplementationFilter(state),
416416
// Use the filtered call node max depth, rather than the preview filtered call node

src/components/flame-graph/FlameGraph.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type StateProps = {
7474
readonly ctssSampleIndexOffset: number;
7575
readonly maxStackDepthPlusOne: number;
7676
readonly timeRange: StartEndRange;
77-
readonly previewSelection: PreviewSelection;
77+
readonly previewSelection: PreviewSelection | null;
7878
readonly flameGraphTiming: FlameGraphTiming;
7979
readonly callTree: CallTree;
8080
readonly callNodeInfo: CallNodeInfo;

src/components/js-tracer/Canvas.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,6 @@ class JsTracerCanvasImpl extends React.PureComponent<Props, State> {
608608
// const { markers, updatePreviewSelection } = this.props;
609609
// const marker = markers[eventIndex];
610610
// updatePreviewSelection({
611-
// hasSelection: true,
612611
// isModifying: false,
613612
// selectionStart: marker.start,
614613
// selectionEnd: marker.start + marker.dur,

src/components/js-tracer/Chart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type StateProps = {
5353
readonly stringTable: StringTable;
5454
readonly timeRange: StartEndRange;
5555
readonly threadsKey: ThreadsKey;
56-
readonly previewSelection: PreviewSelection;
56+
readonly previewSelection: PreviewSelection | null;
5757
};
5858

5959
type Props = ConnectedProps<OwnProps, StateProps, DispatchProps>;

src/components/marker-chart/Canvas.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,6 @@ class MarkerChartCanvasImpl extends React.PureComponent<Props> {
775775
);
776776

777777
updatePreviewSelection({
778-
hasSelection: true,
779778
isModifying: false,
780779
selectionStart: start,
781780
selectionEnd: end,

src/components/marker-chart/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type StateProps = {
5656
readonly markerListLength: number;
5757
readonly timeRange: StartEndRange;
5858
readonly threadsKey: ThreadsKey;
59-
readonly previewSelection: PreviewSelection;
59+
readonly previewSelection: PreviewSelection | null;
6060
readonly rightClickedMarkerIndex: MarkerIndex | null;
6161
readonly selectedMarkerIndex: MarkerIndex | null;
6262
};

src/components/network-chart/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919

2020
import {
2121
getScrollToSelectionGeneration,
22-
getPreviewSelection,
22+
getPreviewSelectionIsBeingModified,
2323
getPreviewSelectionRange,
2424
} from '../../selectors/profile';
2525
import { selectedThreadSelectors } from '../../selectors/per-thread';
@@ -422,7 +422,7 @@ export const NetworkChart = explicitConnect<
422422
hoveredMarkerIndexFromState:
423423
selectedThreadSelectors.getHoveredMarkerIndex(state),
424424
timeRange: getPreviewSelectionRange(state),
425-
disableOverscan: getPreviewSelection(state).isModifying,
425+
disableOverscan: getPreviewSelectionIsBeingModified(state),
426426
threadsKey: getSelectedThreadsKey(state),
427427
}),
428428
mapDispatchToProps: {

0 commit comments

Comments
 (0)