Skip to content

Commit 0eac01a

Browse files
author
Brian Vaughn
authored
Added missing Flow type coverage to DevTools context menu (#17733)
The param should probably be a generic type, but I'm not sure how to satisfy Flow with the current top-level Map. At least this adds basic coverage (which was missing before, oops).
1 parent f887d1a commit 0eac01a

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
110
import React, {
211
useContext,
312
useEffect,
@@ -10,7 +19,7 @@ import {RegistryContext} from './Contexts';
1019

1120
import styles from './ContextMenu.css';
1221

13-
function respositionToFit(element, pageX, pageY) {
22+
function respositionToFit(element: HTMLElement, pageX: number, pageY: number) {
1423
const ownerWindow = element.ownerDocument.defaultView;
1524
if (element !== null) {
1625
if (pageY + element.offsetHeight >= ownerWindow.innerHeight) {
@@ -43,7 +52,7 @@ const HIDDEN_STATE = {
4352
};
4453

4554
type Props = {|
46-
children: React$Node,
55+
children: (data: Object) => React$Node,
4756
id: string,
4857
|};
4958

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
110
import React, {useContext} from 'react';
211
import {RegistryContext} from './Contexts';
312

413
import styles from './ContextMenuItem.css';
514

615
type Props = {|
716
children: React$Node,
8-
onClick: Object => void,
17+
onClick: () => void,
918
title: string,
1019
|};
1120

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

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
110
import {createContext} from 'react';
211

3-
export type ShowFn = ({data: Object, pageX: number, pageY: number}) => void;
12+
export type ShowFn = ({|data: Object, pageX: number, pageY: number|}) => void;
413
export type HideFn = () => void;
514

6-
const idToShowFnMap = new Map();
7-
const idToHideFnMap = new Map();
15+
const idToShowFnMap = new Map<string, ShowFn>();
16+
const idToHideFnMap = new Map<string, HideFn>();
817

918
let currentHideFn = null;
1019

@@ -41,8 +50,8 @@ function registerMenu(id: string, showFn: ShowFn, hideFn: HideFn) {
4150
idToHideFnMap.set(id, hideFn);
4251

4352
return function unregisterMenu() {
44-
idToShowFnMap.delete(id, showFn);
45-
idToHideFnMap.delete(id, hideFn);
53+
idToShowFnMap.delete(id);
54+
idToHideFnMap.delete(id);
4655
};
4756
}
4857

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

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
110
import {useContext, useEffect} from 'react';
211
import {RegistryContext} from './Contexts';
312

4-
export default function useContextMenu({data, id, ref}) {
13+
import type {ElementRef} from 'react';
14+
15+
export default function useContextMenu({
16+
data,
17+
id,
18+
ref,
19+
}: {|
20+
data: Object,
21+
id: string,
22+
ref: ElementRef<HTMLElement>,
23+
|}) {
524
const {showMenu} = useContext(RegistryContext);
625

726
useEffect(

0 commit comments

Comments
 (0)