Skip to content

Commit

Permalink
Increase flow type coverage of many files
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatum committed Jul 13, 2018
1 parent 34d872b commit 23d43e5
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 73 deletions.
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow

import React from 'react';
import { render } from 'react-dom';
Expand All @@ -12,11 +13,12 @@ import {
addDataToWindowObject,
logFriendlyPreamble,
} from './utils/window-console';
import { ensureExists } from './utils/flow';

// Mock out Google Analytics for anything that's not production so that we have run-time
// code coverage in development and testing.
if (process.env.NODE_ENV === 'development') {
window.ga = (event, ...payload) => {
window.ga = (event: string, ...payload: mixed[]) => {
const style = 'color: #FF6D00; font-weight: bold';
console.log(`[analytics] %c"${event}"`, style, ...payload);
};
Expand All @@ -39,7 +41,13 @@ window.geckoProfilerPromise = new Promise(function(resolve) {

const store = createStore();

render(<Root store={store} />, document.getElementById('root'));
render(
<Root store={store} />,
ensureExists(
document.getElementById('root'),
'Unable to find the DOM element to attach the React element to.'
)
);

addDataToWindowObject(store.getState);
if (process.env.NODE_ENV === 'production') {
Expand Down
8 changes: 1 addition & 7 deletions src/profile-logic/process-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { getContainingLibrary } from './symbolication';
import { UniqueStringArray } from '../utils/unique-string-array';
import { resourceTypes, emptyExtensions } from './profile-data';
import { provideHostSide } from '../utils/promise-worker';
import { immutableUpdate } from '../utils/flow';
import {
CURRENT_VERSION,
Expand Down Expand Up @@ -688,7 +687,7 @@ function _processThread(
tid: thread.tid,
pid: thread.pid,
libs,
pausedRanges,
pausedRanges: pausedRanges || [],
frameTable,
funcTable,
resourceTable,
Expand Down Expand Up @@ -926,8 +925,3 @@ export class ProfileProcessor {
});
}
}

export const ProfileProcessorThreaded = provideHostSide(
'profile-processor-worker.js',
['processProfile']
);
7 changes: 4 additions & 3 deletions src/profile-logic/profile-store.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow

export function uploadBinaryProfileData(
data,
progressChangeCallback = undefined
) {
data: string,
progressChangeCallback?: number => void
): Promise<string> {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();

Expand Down
15 changes: 10 additions & 5 deletions src/profile-logic/range-filters.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow

export function parseRangeFilters(stringValue = '') {
import type { StartEndRange } from '../types/units';

export function parseRangeFilters(stringValue: string = ''): StartEndRange[] {
if (!stringValue) {
return [];
}
Expand All @@ -11,11 +14,13 @@ export function parseRangeFilters(stringValue = '') {
if (!m) {
return { start: 0, end: 1000 };
}
return { start: m[1] * 1000, end: m[2] * 1000 };
return { start: Number(m[1]) * 1000, end: Number(m[2]) * 1000 };
});
}

export function stringifyRangeFilters(arrayValue = []) {
export function stringifyRangeFilters(
arrayValue: StartEndRange[] = []
): string {
return arrayValue
.map(({ start, end }) => {
const startStr = (start / 1000).toFixed(4);
Expand All @@ -25,7 +30,7 @@ export function stringifyRangeFilters(arrayValue = []) {
.join('~');
}

export function getFormattedTimeLength(length) {
export function getFormattedTimeLength(length: number): string {
if (length >= 10000) {
return `${(length / 1000).toFixed(0)} sec`;
}
Expand All @@ -35,7 +40,7 @@ export function getFormattedTimeLength(length) {
return `${length.toFixed(0)} ms`;
}

export function getRangeFilterLabels(rangeFilters) {
export function getRangeFilterLabels(rangeFilters: StartEndRange[]): string[] {
const labels = rangeFilters.map(range =>
getFormattedTimeLength(range.end - range.start)
);
Expand Down
8 changes: 0 additions & 8 deletions src/profile-logic/symbol-store-db-worker.js

This file was deleted.

5 changes: 5 additions & 0 deletions src/test/fixtures/mocks/file-mock.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// @flow
export default 'test-file-stub';
1 change: 1 addition & 0 deletions src/test/fixtures/mocks/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// @flow
export function createImageMock() {
function Image() {
instances.push(this);
Expand Down
5 changes: 5 additions & 0 deletions src/test/fixtures/mocks/style-mock.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// @flow
export default {};
1 change: 1 addition & 0 deletions src/types/globals/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ declare class Window extends EventTarget {
ga?: GoogleAnalytics;
// perf.html and Gecko Profiler Addon
geckoProfilerPromise: Promise<GeckoProfiler>;
connectToGeckoProfiler: GeckoProfiler => void;
geckoProfilerAddonInstalled?: () => void;
isGeckoProfilerAddonInstalled?: boolean;
InstallTrigger?: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow

import { ProfileProcessor } from './process-profile';
import { provideWorkerSide } from '../utils/promise-worker';
declare module 'photon-colors' {
declare module.exports: any;
}

provideWorkerSide(self, ProfileProcessor);
declare module 'photon-colors/photon-colors.css' {
declare module.exports: any;
}
39 changes: 0 additions & 39 deletions src/types/libdef/npm/photon-colors_vx.x.x.js

This file was deleted.

7 changes: 1 addition & 6 deletions src/types/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ export type ZippedProfilesState = {
expandedZipFileIndexes: Array<IndexIntoZipFileTable | null>,
};

export type RangeFilterState = {
start: number,
end: number,
};

export type UrlState = {|
dataSource: DataSource,
hash: string,
Expand All @@ -131,7 +126,7 @@ export type UrlState = {|
profileSpecific: {|
implementation: ImplementationFilter,
invertCallstack: boolean,
rangeFilters: RangeFilterState[],
rangeFilters: StartEndRange[],
selectedThread: ThreadIndex | null,
callTreeSearchString: string,
threadOrder: ThreadIndex[],
Expand Down

0 comments on commit 23d43e5

Please sign in to comment.