Skip to content

Commit e54054b

Browse files
committed
Flow: add simple explicit export types to Devtools
1 parent 271bf90 commit e54054b

File tree

133 files changed

+275
-163
lines changed

Some content is hidden

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

133 files changed

+275
-163
lines changed

packages/react-devtools-core/src/standalone.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ function initialize(socket: WebSocket) {
266266

267267
let startServerTimeoutID: TimeoutID | null = null;
268268

269-
function connectToSocket(socket: WebSocket) {
269+
function connectToSocket(socket: WebSocket): {close(): void} {
270270
socket.onerror = err => {
271271
onDisconnected();
272272
log.error('Error with websocket connection', err);
@@ -298,7 +298,7 @@ function startServer(
298298
host?: string = 'localhost',
299299
httpsOptions?: ServerOptions,
300300
loggerOptions?: LoggerOptions,
301-
) {
301+
): {close(): void} {
302302
registerDevToolsEventLogger(loggerOptions?.surface ?? 'standalone');
303303

304304
const useHttps = !!httpsOptions;

packages/react-devtools-shared/src/backend/views/utils.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function getOwnerIframe(node: HTMLElement): HTMLElement | null {
3939

4040
// Get a bounding client rect for a node, with an
4141
// offset added to compensate for its border.
42-
export function getBoundingClientRectWithBorderOffset(node: HTMLElement) {
42+
export function getBoundingClientRectWithBorderOffset(node: HTMLElement): Rect {
4343
const dimensions = getElementDimensions(node);
4444
return mergeRectOffsets([
4545
node.getBoundingClientRect(),
@@ -109,7 +109,22 @@ export function getNestedBoundingClientRect(
109109
}
110110
}
111111

112-
export function getElementDimensions(domElement: Element) {
112+
export function getElementDimensions(
113+
domElement: Element,
114+
): {
115+
borderBottom: number,
116+
borderLeft: number,
117+
borderRight: number,
118+
borderTop: number,
119+
marginBottom: number,
120+
marginLeft: number,
121+
marginRight: number,
122+
marginTop: number,
123+
paddingBottom: number,
124+
paddingLeft: number,
125+
paddingRight: number,
126+
paddingTop: number,
127+
} {
113128
const calculatedStyle = window.getComputedStyle(domElement);
114129
return {
115130
borderLeft: parseInt(calculatedStyle.borderLeftWidth, 10),

packages/react-devtools-shared/src/bridge.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ class Bridge<
375375
}
376376
}
377377

378-
_flush = () => {
378+
_flush: () => void = () => {
379379
// This method is used after the bridge is marked as destroyed in shutdown sequence,
380380
// so we do not bail out if the bridge marked as destroyed.
381381
// It is a private method that the bridge ensures is only called at the right times.
@@ -400,7 +400,7 @@ class Bridge<
400400

401401
// Temporarily support older standalone backends by forwarding "overrideValueAtPath" commands
402402
// to the older message types they may be listening to.
403-
overrideValueAtPath = ({
403+
overrideValueAtPath: OverrideValueAtPath => void = ({
404404
id,
405405
path,
406406
rendererID,

packages/react-devtools-shared/src/constants.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,11 @@ export const THEME_STYLES: {[style: Theme | DisplayDensity]: any, ...} = {
395395
//
396396
// Sometimes the inline target is rendered before root styles are applied,
397397
// which would result in e.g. NaN itemSize being passed to react-window list.
398-
const COMFORTABLE_LINE_HEIGHT = parseInt(
398+
const COMFORTABLE_LINE_HEIGHT: number = parseInt(
399399
THEME_STYLES.comfortable['--line-height-data'],
400400
10,
401401
);
402-
const COMPACT_LINE_HEIGHT = parseInt(
402+
const COMPACT_LINE_HEIGHT: number = parseInt(
403403
THEME_STYLES.compact['--line-height-data'],
404404
10,
405405
);

packages/react-devtools-shared/src/devtools/ContextMenu/Contexts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function showMenu({
6161
}
6262
}
6363

64-
function registerMenu(id: string, showFn: ShowFn, hideFn: HideFn) {
64+
function registerMenu(id: string, showFn: ShowFn, hideFn: HideFn): () => void {
6565
if (idToShowFnMap.has(id)) {
6666
throw Error(`Context menu with id "${id}" already registered.`);
6767
}

packages/react-devtools-shared/src/devtools/utils.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import type {Element} from './views/Components/types';
1313
import type {StateContext} from './views/Components/TreeContext';
1414
import type Store from './store';
1515

16-
export function printElement(element: Element, includeWeight: boolean = false) {
16+
export function printElement(
17+
element: Element,
18+
includeWeight: boolean = false,
19+
): string {
1720
let prefix = ' ';
1821
if (element.children.length > 0) {
1922
prefix = element.isCollapsed ? '▸' : '▾';
@@ -44,7 +47,7 @@ export function printElement(element: Element, includeWeight: boolean = false) {
4447
export function printOwnersList(
4548
elements: Array<Element>,
4649
includeWeight: boolean = false,
47-
) {
50+
): string {
4851
return elements
4952
.map(element => printElement(element, includeWeight))
5053
.join('\n');
@@ -54,7 +57,7 @@ export function printStore(
5457
store: Store,
5558
includeWeight: boolean = false,
5659
state: StateContext | null = null,
57-
) {
60+
): string {
5861
const snapshotLines = [];
5962

6063
let rootWeight = 0;
@@ -172,7 +175,7 @@ export function smartParse(value: any) {
172175
}
173176
}
174177

175-
export function smartStringify(value: any) {
178+
export function smartStringify(value: any): string {
176179
if (typeof value === 'number') {
177180
if (Number.isNaN(value)) {
178181
return 'NaN';

packages/react-devtools-shared/src/devtools/views/ButtonIcon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Props = {
4646
type: IconType,
4747
};
4848

49-
export default function ButtonIcon({className = '', type}: Props) {
49+
export default function ButtonIcon({className = '', type}: Props): React.Node {
5050
let pathData = null;
5151
switch (type) {
5252
case 'add':

packages/react-devtools-shared/src/devtools/views/Components/Badge.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default function Badge({
2525
hocDisplayNames,
2626
type,
2727
children,
28-
}: Props) {
28+
}: Props): React.Node {
2929
if (hocDisplayNames === null || hocDisplayNames.length === 0) {
3030
return null;
3131
}

packages/react-devtools-shared/src/devtools/views/Components/CannotSuspendWarningMessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
ElementTypeSuspense,
1616
} from 'react-devtools-shared/src/types';
1717

18-
export default function CannotSuspendWarningMessage() {
18+
export default function CannotSuspendWarningMessage(): React.Node {
1919
const store = useContext(StoreContext);
2020
const areSuspenseElementsHidden = !!store.componentFilters.find(
2121
filter =>

packages/react-devtools-shared/src/devtools/views/Components/ComponentSearchInput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import SearchInput from '../SearchInput';
1515

1616
type Props = {};
1717

18-
export default function ComponentSearchInput(props: Props) {
18+
export default function ComponentSearchInput(props: Props): React.Node {
1919
const {searchIndex, searchResults, searchText} = useContext(TreeStateContext);
2020
const dispatch = useContext(TreeDispatcherContext);
2121

0 commit comments

Comments
 (0)