Skip to content

Commit a148dac

Browse files
authored
Change implementation of withChartViewport (#5542)
This simplifies the types a bit, making it easier to port to TypeScript. I've split it into two commits so that the indentation change doesn't distract from the code changes. The only real change here is the splitting of the inner component into a `ChartViewportFunctionComponent` and a `ChartViewportImpl<ChartProps>` component. The only purpose of the function component is to take the wrapped component `chart` from the closure scope and put it into a prop of the Impl component.
2 parents 55a1cc0 + 339452a commit a148dac

File tree

5 files changed

+689
-719
lines changed

5 files changed

+689
-719
lines changed

src/components/flame-graph/Canvas.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
// @flow
66
import * as React from 'react';
77
import memoize from 'memoize-immutable';
8-
import {
9-
withChartViewport,
10-
type WithChartViewport,
11-
type Viewport,
12-
} from '../shared/chart/Viewport';
8+
import { withChartViewport, type Viewport } from '../shared/chart/Viewport';
139
import { ChartCanvas } from '../shared/chart/Canvas';
1410
import { FastFillStyle } from '../../utils';
1511
import TextMeasurement from '../../utils/text-measurement';
@@ -525,7 +521,5 @@ class FlameGraphCanvasImpl extends React.PureComponent<Props> {
525521
}
526522
}
527523

528-
export const FlameGraphCanvas = (withChartViewport: WithChartViewport<
529-
OwnProps,
530-
Props,
531-
>)(FlameGraphCanvasImpl);
524+
export const FlameGraphCanvas =
525+
withChartViewport<OwnProps>(FlameGraphCanvasImpl);

src/components/js-tracer/Canvas.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
} from 'firefox-profiler/app-logic/constants';
1313
import {
1414
withChartViewport,
15-
type WithChartViewport,
1615
type Viewport,
1716
} from 'firefox-profiler/components/shared/chart/Viewport';
1817
import { ChartCanvas } from 'firefox-profiler/components/shared/chart/Canvas';
@@ -657,7 +656,4 @@ class JsTracerCanvasImpl extends React.PureComponent<Props, State> {
657656
}
658657
}
659658

660-
export const JsTracerCanvas = (withChartViewport: WithChartViewport<
661-
OwnProps,
662-
Props,
663-
>)(JsTracerCanvasImpl);
659+
export const JsTracerCanvas = withChartViewport<OwnProps>(JsTracerCanvasImpl);

src/components/marker-chart/Canvas.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { GREY_20, GREY_30, BLUE_60, BLUE_80 } from 'photon-colors';
77
import * as React from 'react';
88
import {
99
withChartViewport,
10-
type WithChartViewport,
1110
type Viewport,
1211
} from 'firefox-profiler/components/shared/chart/Viewport';
1312
import { ChartCanvas } from 'firefox-profiler/components/shared/chart/Canvas';
@@ -826,7 +825,6 @@ class MarkerChartCanvasImpl extends React.PureComponent<Props> {
826825
}
827826
}
828827

829-
export const MarkerChartCanvas = (withChartViewport: WithChartViewport<
830-
OwnProps,
831-
Props,
832-
>)(MarkerChartCanvasImpl);
828+
export const MarkerChartCanvas = withChartViewport<OwnProps>(
829+
MarkerChartCanvasImpl
830+
);

0 commit comments

Comments
 (0)