Rename Profiler types to disambiguate which is Frontend and Backend
Flow IDE shows the original type, not the file-scoped alias, so it's confusing to see incompatible variables that have types with the same name. This started from `src/devtools/ProfilingCache.js` where `ProfilingSummary` was incompatible, but I decided to make a bigger change for consistency and to avoid similar mistakes in the future.
Ivan Babak committed
Apr 28, 2019 at 04:28 UTC
d3e5fcd81cc74a97bd719f39d7886303490ba58a
13 files changed
+139
-107
src/backend/renderer.js
+20
-14
@@ -28,17 +28,17 @@ import { getUID } from '../utils';
28
import { inspectHooksOfFiber } from './ReactDebugHooks';
29
30
import type {
31
- CommitDetails,
31
+ CommitDetailsBackend,
32
DevToolsHook,
33
Fiber,
34
- FiberCommits,
34
+ FiberCommitsBackend,
35
FiberData,
36
- Interaction,
37
- Interactions,
38
- InteractionWithCommits,
36
+ InteractionBackend,
37
+ InteractionsBackend,
38
+ InteractionWithCommitsBackend,
39
PathFrame,
40
PathMatch,
41
- ProfilingSummary,
41
+ ProfilingSummaryBackend,
42
ReactRenderer,
43
RendererInterface,
44
} from './types';
@@ -1160,7 +1160,7 @@ export function attach(
1160
actualDurations: [],
1161
commitTime: performance.now() - profilingStartTime,
1162
interactions: Array.from(root.memoizedInteractions).map(
1163
- (interaction: Interaction) => ({
1163
+ (interaction: InteractionBackend) => ({
1164
...interaction,
1165
timestamp: interaction.timestamp - profilingStartTime,
1166
})
@@ -1202,7 +1202,7 @@ export function attach(
1202
actualDurations: [],
1203
commitTime: performance.now() - profilingStartTime,
1204
interactions: Array.from(root.memoizedInteractions).map(
1205
- (interaction: Interaction) => ({
1205
+ (interaction: InteractionBackend) => ({
1206
...interaction,
1207
timestamp: interaction.timestamp - profilingStartTime,
1208
})
@@ -1789,7 +1789,7 @@ export function attach(
1789
type CommitProfilingData = {|
1790
actualDurations: Array<number>,
1791
commitTime: number,
1792
- interactions: Array<Interaction>,
1792
+ interactions: Array<InteractionBackend>,
1793
maxActualDuration: number,
1794
|};
1795
@@ -1805,7 +1805,7 @@ export function attach(
1805
function getCommitDetails(
1806
rootID: number,
1807
commitIndex: number
1808
- ): CommitDetails {
1808
+ ): CommitDetailsBackend {
1809
const commitProfilingMetadata = ((rootToCommitProfilingMetadataMap: any): CommitProfilingMetadataMap).get(
1810
rootID
1811
);
@@ -1833,7 +1833,10 @@ export function attach(
1833
};
1834
}
1835
1836
- function getFiberCommits(rootID: number, fiberID: number): FiberCommits {
1836
+ function getFiberCommits(
1837
+ rootID: number,
1838
+ fiberID: number
1839
+ ): FiberCommitsBackend {
1840
const commitProfilingMetadata = ((rootToCommitProfilingMetadataMap: any): CommitProfilingMetadataMap).get(
1841
rootID
1842
);
@@ -1866,12 +1869,15 @@ export function attach(
1869
};
1870
}
1871
1869
- function getInteractions(rootID: number): Interactions {
1872
+ function getInteractions(rootID: number): InteractionsBackend {
1873
const commitProfilingMetadata = ((rootToCommitProfilingMetadataMap: any): CommitProfilingMetadataMap).get(
1874
rootID
1875
);
1876
if (commitProfilingMetadata != null) {
1874
- const interactionsMap: Map<number, InteractionWithCommits> = new Map();
1877
+ const interactionsMap: Map<
1878
+ number,
1879
+ InteractionWithCommitsBackend
1880
+ > = new Map();
1881
1882
commitProfilingMetadata.forEach((commitProfilingData, commitIndex) => {
1883
commitProfilingData.interactions.forEach(interaction => {
@@ -1921,7 +1927,7 @@ export function attach(
1927
};
1928
}
1929
1924
- function getProfilingSummary(rootID: number): ProfilingSummary {
1930
+ function getProfilingSummary(rootID: number): ProfilingSummaryBackend {
1931
const interactions = new Set();
1932
const commitDurations = [];
1933
const commitTimes = [];
src/backend/types.js
+16
-13
@@ -53,36 +53,36 @@ export type ReactRenderer = {
53
currentDispatcherRef?: {| current: null | Dispatcher |},
54
};
55
56
-export type Interaction = {|
56
+export type InteractionBackend = {|
57
id: number,
58
name: string,
59
timestamp: number,
60
|};
61
62
-export type CommitDetails = {|
62
+export type CommitDetailsBackend = {|
63
actualDurations: Array<number>,
64
commitIndex: number,
65
- interactions: Array<Interaction>,
65
+ interactions: Array<InteractionBackend>,
66
rootID: number,
67
|};
68
69
-export type FiberCommits = {|
69
+export type FiberCommitsBackend = {|
70
commitDurations: Array<number>,
71
fiberID: number,
72
rootID: number,
73
|};
74
75
-export type InteractionWithCommits = {|
76
- ...Interaction,
75
+export type InteractionWithCommitsBackend = {|
76
+ ...InteractionBackend,
77
commits: Array<number>,
78
|};
79
80
-export type Interactions = {|
81
- interactions: Array<InteractionWithCommits>,
80
+export type InteractionsBackend = {|
81
+ interactions: Array<InteractionWithCommitsBackend>,
82
rootID: number,
83
|};
84
85
-export type ProfilingSummary = {|
85
+export type ProfilingSummaryBackend = {|
86
commitDurations: Array<number>,
87
commitTimes: Array<number>,
88
initialTreeBaseDurations: Array<number>,
@@ -106,15 +106,18 @@ export type RendererInterface = {
106
findNativeByFiberID: (id: number) => ?NativeType,
107
flushInitialOperations: () => void,
108
getBestMatchForTrackedPath: () => PathMatch | null,
109
- getCommitDetails: (rootID: number, commitIndex: number) => CommitDetails,
109
+ getCommitDetails: (
110
+ rootID: number,
111
+ commitIndex: number
112
+ ) => CommitDetailsBackend,
113
getFiberIDFromNative: (
114
component: NativeType,
115
findNearestUnfilteredAncestor?: boolean
116
) => number | null,
114
- getFiberCommits: (rootID: number, fiberID: number) => FiberCommits,
115
- getInteractions: (rootID: number) => Interactions,
117
+ getFiberCommits: (rootID: number, fiberID: number) => FiberCommitsBackend,
118
+ getInteractions: (rootID: number) => InteractionsBackend,
119
getProfilingDataForDownload: (rootID: number) => Object,
117
- getProfilingSummary: (rootID: number) => ProfilingSummary,
120
+ getProfilingSummary: (rootID: number) => ProfilingSummaryBackend,
121
getPathForElement: (id: number) => Array<PathFrame> | null,
122
handleCommitFiberRoot: (fiber: Object) => void,
123
handleCommitFiberUnmount: (fiber: Object) => void,
src/devtools/ProfilingCache.js
+11
-11
@@ -22,18 +22,18 @@ import {
22
import type { Resource } from './cache';
23
import type { Bridge } from '../types';
24
import type {
25
- CommitDetails as CommitDetailsBackend,
26
- FiberCommits as FiberCommitsBackend,
27
- Interactions as InteractionsBackend,
28
- ProfilingSummary as ProfilingSummaryBackend,
25
+ CommitDetailsBackend,
26
+ FiberCommitsBackend,
27
+ InteractionsBackend,
28
+ ProfilingSummaryBackend,
29
} from 'src/backend/types';
30
import type {
31
- CommitDetails as CommitDetailsFrontend,
32
- FiberCommits as FiberCommitsFrontend,
33
- Interactions as InteractionsFrontend,
34
- InteractionWithCommits,
35
- CommitTree as CommitTreeFrontend,
36
- ProfilingSummary as ProfilingSummaryFrontend,
31
+ CommitDetailsFrontend,
32
+ FiberCommitsFrontend,
33
+ InteractionsFrontend,
34
+ InteractionWithCommitsFrontend,
35
+ CommitTreeFrontend,
36
+ ProfilingSummaryFrontend,
37
} from 'src/devtools/views/Profiler/types';
38
import type { ChartData as FlamegraphChartData } from 'src/devtools/views/Profiler/FlamegraphChartBuilder';
39
import type { ChartData as InteractionsChartData } from 'src/devtools/views/Profiler/InteractionsChartBuilder';
@@ -273,7 +273,7 @@ export default class ProfilingCache {
273
profilingSummary,
274
rootID,
275
}: {|
276
- interactions: Array<InteractionWithCommits>,
276
+ interactions: Array<InteractionWithCommitsFrontend>,
277
profilingSummary: ProfilingSummaryFrontend,
278
|}): InteractionsChartData =>
279
getInteractionsChartData({
src/devtools/views/Profiler/CommitFlamegraph.js
+9
-7
@@ -13,7 +13,7 @@ import { StoreContext } from '../context';
13
import styles from './CommitFlamegraph.css';
14
15
import type { ChartData, ChartNode } from './FlamegraphChartBuilder';
16
-import type { CommitDetails, CommitTree } from './types';
16
+import type { CommitDetailsFrontend, CommitTreeFrontend } from './types';
17
18
export type ItemData = {|
19
chartData: ChartData,
@@ -43,8 +43,8 @@ export default function CommitFlamegraphAutoSizer(_: {||}) {
43
rootID: ((rootID: any): number),
44
});
45
46
- let commitDetails: CommitDetails | null = null;
47
- let commitTree: CommitTree | null = null;
46
+ let commitDetails: CommitDetailsFrontend | null = null;
47
+ let commitTree: CommitTreeFrontend | null = null;
48
let chartData: ChartData | null = null;
49
if (selectedCommitIndex !== null) {
50
commitDetails = profilingCache.CommitDetails.read({
@@ -75,10 +75,12 @@ export default function CommitFlamegraphAutoSizer(_: {||}) {
75
<div className={styles.Container} onClick={deselectCurrentFiber}>
76
<AutoSizer>
77
{({ height, width }) => (
78
+ // Force Flow types to avoid checking for `null` here because there's no static proof that
79
+ // by the time this render prop function is called, the values of the `let` variables have not changed.
80
<CommitFlamegraph
81
chartData={((chartData: any): ChartData)}
80
- commitDetails={((commitDetails: any): CommitDetails)}
81
- commitTree={((commitTree: any): CommitTree)}
82
+ commitDetails={((commitDetails: any): CommitDetailsFrontend)}
83
+ commitTree={((commitTree: any): CommitTreeFrontend)}
84
height={height}
85
width={width}
86
/>
@@ -93,8 +95,8 @@ export default function CommitFlamegraphAutoSizer(_: {||}) {
95
96
type Props = {|
97
chartData: ChartData,
96
- commitDetails: CommitDetails,
97
- commitTree: CommitTree,
98
+ commitDetails: CommitDetailsFrontend,
99
+ commitTree: CommitTreeFrontend,
100
height: number,
101
width: number,
102
|};
src/devtools/views/Profiler/CommitRanked.js
+7
-7
@@ -13,7 +13,7 @@ import { StoreContext } from '../context';
13
import styles from './CommitRanked.css';
14
15
import type { ChartData } from './RankedChartBuilder';
16
-import type { CommitDetails, CommitTree } from './types';
16
+import type { CommitDetailsFrontend, CommitTreeFrontend } from './types';
17
18
export type ItemData = {|
19
chartData: ChartData,
@@ -43,8 +43,8 @@ export default function CommitRankedAutoSizer(_: {||}) {
43
rootID: ((rootID: any): number),
44
});
45
46
- let commitDetails: CommitDetails | null = null;
47
- let commitTree: CommitTree | null = null;
46
+ let commitDetails: CommitDetailsFrontend | null = null;
47
+ let commitTree: CommitTreeFrontend | null = null;
48
let chartData: ChartData | null = null;
49
if (selectedCommitIndex !== null) {
50
commitDetails = profilingCache.CommitDetails.read({
@@ -77,8 +77,8 @@ export default function CommitRankedAutoSizer(_: {||}) {
77
{({ height, width }) => (
78
<CommitRanked
79
chartData={((chartData: any): ChartData)}
80
- commitDetails={((commitDetails: any): CommitDetails)}
81
- commitTree={((commitTree: any): CommitTree)}
80
+ commitDetails={((commitDetails: any): CommitDetailsFrontend)}
81
+ commitTree={((commitTree: any): CommitTreeFrontend)}
82
height={height}
83
width={width}
84
/>
@@ -93,8 +93,8 @@ export default function CommitRankedAutoSizer(_: {||}) {
93
94
type Props = {|
95
chartData: ChartData,
96
- commitDetails: CommitDetails,
97
- commitTree: CommitTree,
96
+ commitDetails: CommitDetailsFrontend,
97
+ commitTree: CommitTreeFrontend,
98
height: number,
99
width: number,
100
|};
src/devtools/views/Profiler/CommitTreeBuilder.js
+21
-15
@@ -13,9 +13,9 @@ import Store from 'src/devtools/store';
13
14
import type { ElementType } from 'src/devtools/types';
15
import type {
16
- CommitTree,
17
- Node,
18
- ProfilingSummary as ProfilingSummaryFrontend,
16
+ CommitTreeFrontend,
17
+ CommitTreeNodeFrontend,
18
+ ProfilingSummaryFrontend,
19
} from 'src/devtools/views/Profiler/types';
20
21
const debug = (methodName, ...args) => {
@@ -29,7 +29,7 @@ const debug = (methodName, ...args) => {
29
}
30
};
31
32
-const rootToCommitTreeMap: Map<number, Array<CommitTree>> = new Map();
32
+const rootToCommitTreeMap: Map<number, Array<CommitTreeFrontend>> = new Map();
33
34
export function getCommitTree({
35
commitIndex,
@@ -39,7 +39,7 @@ export function getCommitTree({
39
commitIndex: number,
40
profilingSummary: ProfilingSummaryFrontend,
41
store: Store,
42
-|}): CommitTree {
42
+|}): CommitTreeFrontend {
43
const { rootID } = profilingSummary;
44
45
if (!rootToCommitTreeMap.has(rootID)) {
@@ -48,7 +48,7 @@ export function getCommitTree({
48
49
const commitTrees = ((rootToCommitTreeMap.get(
50
rootID
51
- ): any): Array<CommitTree>);
51
+ ): any): Array<CommitTreeFrontend>);
52
53
if (commitIndex < commitTrees.length) {
54
return commitTrees[commitIndex];
@@ -120,7 +120,7 @@ export function getCommitTree({
120
function recursivelyIniitliazeTree(
121
id: number,
122
parentID: number,
123
- nodes: Map<number, Node>,
123
+ nodes: Map<number, CommitTreeNodeFrontend>,
124
initialTreeBaseDurations: Map<number, number>,
125
store: Store
126
): void {
@@ -153,15 +153,18 @@ function recursivelyIniitliazeTree(
153
}
154
155
function updateTree(
156
- commitTree: CommitTree,
156
+ commitTree: CommitTreeFrontend,
157
operations: Uint32Array
158
-): CommitTree {
158
+): CommitTreeFrontend {
159
// Clone the original tree so edits don't affect it.
160
const nodes = new Map(commitTree.nodes);
161
162
// Clone nodes before mutating them so edits don't affect them.
163
- const getClonedNode = (id: number): Node => {
164
- const clonedNode = ((Object.assign({}, nodes.get(id)): any): Node);
163
+ const getClonedNode = (id: number): CommitTreeNodeFrontend => {
164
+ const clonedNode = ((Object.assign(
165
+ {},
166
+ nodes.get(id)
167
+ ): any): CommitTreeNodeFrontend);
168
nodes.set(id, clonedNode);
169
return clonedNode;
170
};
@@ -209,7 +212,7 @@ function updateTree(
212
debug('Add', `new root fiber ${id}`);
213
}
214
212
- const node: Node = {
215
+ const node: CommitTreeNodeFrontend = {
216
children: [],
217
displayName: null,
218
id,
@@ -243,7 +246,7 @@ function updateTree(
246
const parentNode = getClonedNode(parentID);
247
parentNode.children = parentNode.children.concat(id);
248
246
- const node: Node = {
249
+ const node: CommitTreeNodeFrontend = {
250
children: [],
251
displayName,
252
id,
@@ -343,7 +346,7 @@ export function invalidateCommitTrees(): void {
346
}
347
348
// DEBUG
346
-const __printTree = (commitTree: CommitTree) => {
349
+const __printTree = (commitTree: CommitTreeFrontend) => {
350
if (__DEBUG__) {
351
const { nodes, rootID } = commitTree;
352
console.group('__printTree()');
@@ -352,7 +355,10 @@ const __printTree = (commitTree: CommitTree) => {
355
const id = queue.shift();
356
const depth = queue.shift();
357
355
- const node = ((nodes.get(id): any): Node);
358
+ const node = nodes.get(id);
359
+ if (node == null) {
360
+ throw Error(`Could not find node with id "${id}" in commit tree`);
361
+ }
362
363
console.log(
364
`${'•'.repeat(depth)}${node.id}:${node.displayName || ''} ${
src/devtools/views/Profiler/FlamegraphChartBuilder.js
+10
-6
@@ -2,7 +2,7 @@
2
3
import { calculateSelfDuration } from './utils';
4
5
-import type { CommitDetails, CommitTree, Node } from './types';
5
+import type { CommitDetailsFrontend, CommitTreeFrontend } from './types';
6
7
export type ChartNode = {|
8
actualDuration: number,
@@ -29,9 +29,9 @@ export function getChartData({
29
commitIndex,
30
commitTree,
31
}: {|
32
- commitDetails: CommitDetails,
32
+ commitDetails: CommitDetailsFrontend,
33
commitIndex: number,
34
- commitTree: CommitTree,
34
+ commitTree: CommitTreeFrontend,
35
|}): ChartData {
36
const { actualDurations, rootID } = commitDetails;
37
const { nodes } = commitTree;
@@ -55,8 +55,7 @@ export function getChartData({
55
) => {
56
idToDepthMap.set(id, currentDepth);
57
58
- const node = ((nodes.get(id): any): Node);
59
-
58
+ const node = nodes.get(id);
59
if (node == null) {
60
throw Error(`Could not find node with id "${id}" in commit tree`);
61
}
@@ -104,7 +103,12 @@ export function getChartData({
103
};
104
105
// Skip over the root; we don't want to show it in the flamegraph.
107
- const root = ((nodes.get(rootID): any): Node);
106
+ const root = nodes.get(rootID);
107
+ if (root == null) {
108
+ throw Error(`Could not find root node with id "${rootID}" in commit tree`);
109
+ }
110
+
111
+ // TODO: Looks like there's an assumption here that a root has only one child. Is that so with a fragment in the root?
112
walkTree(root.children[0]);
113
114
const chartData = {
src/devtools/views/Profiler/Interactions.js
+6
-3
@@ -13,13 +13,16 @@ import styles from './Interactions.css';
13
14
import type { ChartData } from './InteractionsChartBuilder';
15
import type { TabID } from './ProfilerContext';
16
-import type { InteractionWithCommits, ProfilingSummary } from './types';
16
+import type {
17
+ InteractionWithCommitsFrontend,
18
+ ProfilingSummaryFrontend,
19
+} from './types';
20
21
export type ItemData = {|
22
chartData: ChartData,
20
- interactions: Array<InteractionWithCommits>,
23
+ interactions: Array<InteractionWithCommitsFrontend>,
24
labelWidth: number,
22
- profilingSummary: ProfilingSummary,
25
+ profilingSummary: ProfilingSummaryFrontend,
26
scaleX: (value: number, fallbackValue: number) => number,
27
selectedInteractionID: number | null,
28
selectCommitIndex: (id: number | null) => void,
src/devtools/views/Profiler/InteractionsChartBuilder.js
+6
-3
@@ -1,6 +1,9 @@
1
// @flow
2
3
-import type { InteractionWithCommits, ProfilingSummary } from './types';
3
+import type {
4
+ InteractionWithCommitsFrontend,
5
+ ProfilingSummaryFrontend,
6
+} from './types';
7
8
export type ChartData = {|
9
lastInteractionTime: number,
@@ -13,8 +16,8 @@ export function getChartData({
16
interactions,
17
profilingSummary,
18
}: {|
16
- interactions: Array<InteractionWithCommits>,
17
- profilingSummary: ProfilingSummary,
19
+ interactions: Array<InteractionWithCommitsFrontend>,
20
+ profilingSummary: ProfilingSummaryFrontend,
21
|}): ChartData {
22
const { rootID } = profilingSummary;
23
src/devtools/views/Profiler/RankedChartBuilder.js
+4
-4
@@ -2,7 +2,7 @@
2
3
import { calculateSelfDuration } from './utils';
4
5
-import type { CommitDetails, CommitTree, Node } from './types';
5
+import type { CommitDetailsFrontend, CommitTreeFrontend } from './types';
6
7
export type ChartNode = {|
8
id: number,
@@ -23,9 +23,9 @@ export function getChartData({
23
commitIndex,
24
commitTree,
25
}: {|
26
- commitDetails: CommitDetails,
26
+ commitDetails: CommitDetailsFrontend,
27
commitIndex: number,
28
- commitTree: CommitTree,
28
+ commitTree: CommitTreeFrontend,
29
|}): ChartData {
30
const { actualDurations, rootID } = commitDetails;
31
const { nodes } = commitTree;
@@ -39,7 +39,7 @@ export function getChartData({
39
40
const chartNodes: Array<ChartNode> = [];
41
actualDurations.forEach((actualDuration, id) => {
42
- const node = ((nodes.get(id): any): Node);
42
+ const node = nodes.get(id);
43
44
if (node == null) {
45
throw Error(`Could not find node with id "${id}" in commit tree`);
src/devtools/views/Profiler/SidebarInteractions.js
+8
-6
@@ -8,8 +8,6 @@ import { getGradientColor } from './utils';
8
9
import styles from './SidebarInteractions.css';
10
11
-import type { InteractionWithCommits } from './types';
12
-
11
export type Props = {||};
12
13
export default function SidebarInteractions(_: Props) {
@@ -31,6 +29,14 @@ export default function SidebarInteractions(_: Props) {
29
rendererID: ((rendererID: any): number),
30
rootID: ((rootID: any): number),
31
});
32
+ const interaction = interactions.find(
33
+ interaction => interaction.id === selectedInteractionID
34
+ );
35
+ if (interaction == null) {
36
+ throw Error(
37
+ `Could not find interaction by selected interaction id "${selectedInteractionID}"`
38
+ );
39
+ }
40
41
const profilingSummary = profilingCache.ProfilingSummary.read({
42
rendererID: ((rendererID: any): number),
@@ -44,10 +50,6 @@ export default function SidebarInteractions(_: Props) {
50
51
const { commitDurations, commitTimes } = profilingSummary;
52
47
- const interaction = ((interactions.find(
48
- interaction => interaction.id === selectedInteractionID
49
- ): any): InteractionWithCommits);
50
-
53
const viewCommit = (commitIndex: number) => {
54
selectTab('flame-chart');
55
selectCommitIndex(commitIndex);
src/devtools/views/Profiler/types.js
+14
-14
@@ -1,6 +1,6 @@
1
// @flow
2
3
-export type Node = {|
3
+export type CommitTreeNodeFrontend = {|
4
id: number,
5
children: Array<number>,
6
displayName: string | null,
@@ -9,38 +9,38 @@ export type Node = {|
9
treeBaseDuration: number,
10
|};
11
12
-export type CommitTree = {|
13
- nodes: Map<number, Node>,
12
+export type CommitTreeFrontend = {|
13
+ nodes: Map<number, CommitTreeNodeFrontend>,
14
rootID: number,
15
|};
16
17
-export type Interaction = {|
17
+export type InteractionFrontend = {|
18
id: number,
19
name: string,
20
timestamp: number,
21
|};
22
23
-export type InteractionWithCommits = {|
24
- ...Interaction,
23
+export type InteractionWithCommitsFrontend = {|
24
+ ...InteractionFrontend,
25
commits: Array<number>,
26
|};
27
28
-export type Interactions = Array<InteractionWithCommits>;
28
+export type InteractionsFrontend = Array<InteractionWithCommitsFrontend>;
29
30
-export type CommitDetails = {|
30
+export type CommitDetailsFrontend = {|
31
rootID: number,
32
commitIndex: number,
33
actualDurations: Map<number, number>,
34
- interactions: Array<Interaction>,
34
+ interactions: Array<InteractionFrontend>,
35
|};
36
37
-export type FiberCommits = {|
37
+export type FiberCommitsFrontend = {|
38
commitDurations: Array<number>,
39
fiberID: number,
40
rootID: number,
41
|};
42
43
-export type ProfilingSummary = {|
43
+export type ProfilingSummaryFrontend = {|
44
rootID: number,
45
46
// Commit durations
@@ -66,7 +66,7 @@ export type ImportedProfilingData = {|
66
version: number,
67
profilingOperations: Map<number, Array<Uint32Array>>,
68
profilingSnapshot: Map<number, ProfilingSnapshotNode>,
69
- commitDetails: CommitDetails,
70
- interactions: Interactions,
71
- profilingSummary: ProfilingSummary,
69
+ commitDetails: CommitDetailsFrontend,
70
+ interactions: InteractionsFrontend,
71
+ profilingSummary: ProfilingSummaryFrontend,
72
|};
src/devtools/views/Profiler/utils.js
+7
-4
@@ -1,6 +1,6 @@
1
// @flow
2
3
-import type { CommitDetails, CommitTree, Node } from './types';
3
+import type { CommitDetailsFrontend, CommitTreeFrontend } from './types';
4
5
const commitGradient = [
6
'var(--color-commit-gradient-0)',
@@ -17,8 +17,8 @@ const commitGradient = [
17
18
export const calculateSelfDuration = (
19
id: number,
20
- commitTree: CommitTree,
21
- commitDetails: CommitDetails
20
+ commitTree: CommitTreeFrontend,
21
+ commitDetails: CommitDetailsFrontend
22
): number => {
23
const { actualDurations } = commitDetails;
24
const { nodes } = commitTree;
@@ -28,8 +28,11 @@ export const calculateSelfDuration = (
28
}
29
30
let selfDuration = ((actualDurations.get(id): any): number);
31
+ const node = nodes.get(id);
32
+ if (node == null) {
33
+ throw Error(`Could not find node with id "${id}" in commit tree`);
34
+ }
35
32
- const node = ((nodes.get(id): any): Node);
36
node.children.forEach(childID => {
37
if (actualDurations.has(childID)) {
38
selfDuration -= ((actualDurations.get(childID): any): number);