Skip to content

Commit 1faf2e3

Browse files
committed
Remove hasSelection property.
Instead of a PreviewSelection with hasSelection: false, just use null. This makes the PreviewSelection type usable in places where we want to only get objects with an actual selection, and is simpler overall.
1 parent c2a7ec1 commit 1faf2e3

39 files changed

+66
-149
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/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/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/shared/MarkerContextMenu.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type OwnProps = {
5252
type StateProps = {
5353
readonly marker: Marker;
5454
readonly markerIndex: MarkerIndex;
55-
readonly previewSelection: PreviewSelection;
55+
readonly previewSelection: PreviewSelection | null;
5656
readonly committedRange: StartEndRange;
5757
readonly thread: Thread | null;
5858
readonly implementationFilter: ImplementationFilter;
@@ -74,12 +74,11 @@ class MarkerContextMenuImpl extends PureComponent<Props> {
7474
const { updatePreviewSelection, previewSelection, committedRange } =
7575
this.props;
7676

77-
const selectionEnd = previewSelection.hasSelection
77+
const selectionEnd = previewSelection
7878
? previewSelection.selectionEnd
7979
: committedRange.end;
8080

8181
updatePreviewSelection({
82-
hasSelection: true,
8382
isModifying: false,
8483
selectionStart,
8584
selectionEnd,
@@ -90,7 +89,7 @@ class MarkerContextMenuImpl extends PureComponent<Props> {
9089
const { updatePreviewSelection, committedRange, previewSelection } =
9190
this.props;
9291

93-
const selectionStart = previewSelection.hasSelection
92+
const selectionStart = previewSelection
9493
? previewSelection.selectionStart
9594
: committedRange.start;
9695

@@ -102,7 +101,6 @@ class MarkerContextMenuImpl extends PureComponent<Props> {
102101
}
103102

104103
updatePreviewSelection({
105-
hasSelection: true,
106104
isModifying: false,
107105
selectionStart,
108106
selectionEnd,
@@ -137,7 +135,6 @@ class MarkerContextMenuImpl extends PureComponent<Props> {
137135
}
138136

139137
updatePreviewSelection({
140-
hasSelection: true,
141138
isModifying: false,
142139
selectionStart: marker.start,
143140
selectionEnd: marker.end,
@@ -385,11 +382,11 @@ class MarkerContextMenuImpl extends PureComponent<Props> {
385382
const { marker, previewSelection, committedRange } = this.props;
386383
const { data } = marker;
387384

388-
const selectionEnd = previewSelection.hasSelection
385+
const selectionEnd = previewSelection
389386
? previewSelection.selectionEnd
390387
: committedRange.end;
391388

392-
const selectionStart = previewSelection.hasSelection
389+
const selectionStart = previewSelection
393390
? previewSelection.selectionStart
394391
: committedRange.start;
395392

src/components/shared/chart/Viewport.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ type ViewportProps<ChartProps> = {
145145
// The "committed range", whose endpoints correspond to 0 and 1.
146146
readonly timeRange: StartEndRange;
147147
// The preview selection, whose endpoints correspond to viewportLeft and viewportRight.
148-
readonly previewSelection: PreviewSelection;
148+
readonly previewSelection: PreviewSelection | null;
149149
// The left margin. Margins are outside the viewport but inside containerWidth.
150150
readonly marginLeft: CssPixels;
151151
// The right margin. Margins are outside the viewport but inside containerWidth.
@@ -214,7 +214,7 @@ class ChartViewportImpl<OwnProps> extends React.PureComponent<
214214
> {
215215
zoomScrollId: number = 0;
216216
_pendingPreviewSelectionUpdates: Array<
217-
(horizontalViewport: HorizontalViewport) => PreviewSelection
217+
(horizontalViewport: HorizontalViewport) => PreviewSelection | null
218218
> = [];
219219
_container: HTMLDivElement | null = null;
220220
_takeContainerRef = (container: HTMLDivElement) => {
@@ -235,10 +235,10 @@ class ChartViewportImpl<OwnProps> extends React.PureComponent<
235235
}
236236

237237
getHorizontalViewport(
238-
previewSelection: PreviewSelection,
238+
previewSelection: PreviewSelection | null,
239239
timeRange: StartEndRange
240240
) {
241-
if (previewSelection.hasSelection) {
241+
if (previewSelection) {
242242
const { selectionStart, selectionEnd } = previewSelection;
243243
const timeRangeLength = timeRange.end - timeRange.start;
244244
return {
@@ -433,7 +433,7 @@ class ChartViewportImpl<OwnProps> extends React.PureComponent<
433433
* processes all queued updates from a requestAnimationFrame callback.
434434
*/
435435
_addBatchedPreviewSelectionUpdate(
436-
callback: (param: HorizontalViewport) => PreviewSelection
436+
callback: (param: HorizontalViewport) => PreviewSelection | null
437437
) {
438438
if (this._pendingPreviewSelectionUpdates.length === 0) {
439439
requestAnimationFrame(() => this._flushPendingPreviewSelectionUpdates());
@@ -532,14 +532,10 @@ class ChartViewportImpl<OwnProps> extends React.PureComponent<
532532
viewportProps: { timeRange },
533533
} = this.props;
534534
if (newViewportLeft === 0 && newViewportRight === 1) {
535-
return {
536-
hasSelection: false,
537-
isModifying: false,
538-
};
535+
return null;
539536
}
540537
const timeRangeLength = timeRange.end - timeRange.start;
541538
return {
542-
hasSelection: true,
543539
isModifying: false,
544540
selectionStart: timeRange.start + timeRangeLength * newViewportLeft,
545541
selectionEnd: timeRange.start + timeRangeLength * newViewportRight,
@@ -722,10 +718,7 @@ class ChartViewportImpl<OwnProps> extends React.PureComponent<
722718
// Calculate left and right in terms of the unit interval of the profile range.
723719
const viewportLength = viewportRight - viewportLeft;
724720
if (viewportLength >= 1) {
725-
return {
726-
hasSelection: false,
727-
isModifying: false,
728-
};
721+
return null;
729722
}
730723
const viewportPixelWidth = containerWidth - marginLeft - marginRight;
731724
const unitOffsetX = offsetX * (viewportLength / viewportPixelWidth);
@@ -742,7 +735,6 @@ class ChartViewportImpl<OwnProps> extends React.PureComponent<
742735

743736
const timeRangeLength = timeRange.end - timeRange.start;
744737
return {
745-
hasSelection: true,
746738
isModifying: false,
747739
selectionStart: timeRange.start + timeRangeLength * newViewportLeft,
748740
selectionEnd: timeRange.start + timeRangeLength * newViewportRight,

src/components/stack-chart/Canvas.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ class StackChartCanvasImpl extends React.PureComponent<Props> {
641641
const { depth, stackTimingIndex } = hoveredItem;
642642
const { combinedTimingRows, updatePreviewSelection } = this.props;
643643
updatePreviewSelection({
644-
hasSelection: true,
645644
isModifying: false,
646645
selectionStart: combinedTimingRows[depth].start[stackTimingIndex],
647646
selectionEnd: combinedTimingRows[depth].end[stackTimingIndex],

0 commit comments

Comments
 (0)