Improve Flow coverage by reducing typecasts through `any`
There are many unnecessary typecasts through `any` which break the Flow of types across the program. It's more bulletproof to avoid lying to ourselves about types. Also fixed sketchy null check where zero ID would be skipped: ```diff - } else if (selectedElementID) { + } else if (selectedElementID !== null) { ```
This commit is contained in:
parent
abcb613223
commit
d1f6e762e4
|
@ -503,7 +503,7 @@ export default class Store extends EventEmitter {
|
|||
while (current != null) {
|
||||
if (current.parentID === 0) {
|
||||
const rendererID = this._rootIDToRendererID.get(current.id);
|
||||
return rendererID == null ? null : ((rendererID: any): number);
|
||||
return rendererID == null ? null : rendererID;
|
||||
} else {
|
||||
current = this._idToElement.get(current.parentID);
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ type Props = {|
|
|||
height: number,
|
||||
isDimmed?: boolean,
|
||||
label: string,
|
||||
onClick: Function,
|
||||
onDoubleClick?: Function,
|
||||
onClick: (event: SyntheticMouseEvent<*>) => mixed,
|
||||
onDoubleClick?: (event: SyntheticMouseEvent<*>) => mixed,
|
||||
placeLabelAboveNode?: boolean,
|
||||
width: number,
|
||||
x: number,
|
||||
|
|
|
@ -26,7 +26,7 @@ function CommitFlamegraphListItem({ data, index, style }: Props) {
|
|||
const { maxSelfDuration, rows } = chartData;
|
||||
|
||||
const handleClick = useCallback(
|
||||
(event: MouseEvent, id: number, name: string) => {
|
||||
(event: SyntheticMouseEvent<*>, id: number, name: string) => {
|
||||
event.stopPropagation();
|
||||
selectFiber(id, name);
|
||||
},
|
||||
|
|
|
@ -7,7 +7,7 @@ import { useModalDismissSignal } from '../hooks';
|
|||
import styles from './FilterModal.css';
|
||||
|
||||
type Props = {|
|
||||
dismissModal: Function,
|
||||
dismissModal: () => void,
|
||||
|};
|
||||
|
||||
export default function FilterModal({ dismissModal }: Props) {
|
||||
|
@ -19,8 +19,8 @@ export default function FilterModal({ dismissModal }: Props) {
|
|||
} = useContext(ProfilerContext);
|
||||
|
||||
const handleNumberChange = useCallback(
|
||||
({ currentTarget }) => {
|
||||
const newValue = parseFloat(currentTarget.value);
|
||||
(event: SyntheticEvent<HTMLInputElement>) => {
|
||||
const newValue = parseFloat(event.currentTarget.value);
|
||||
setMinCommitDuration(
|
||||
Number.isNaN(newValue) || newValue <= 0 ? 0 : newValue
|
||||
);
|
||||
|
@ -29,9 +29,10 @@ export default function FilterModal({ dismissModal }: Props) {
|
|||
);
|
||||
|
||||
const handleEnabledChange = useCallback(
|
||||
({ currentTarget }) => {
|
||||
setIsCommitFilterEnabled(currentTarget.checked);
|
||||
if (currentTarget.checked) {
|
||||
(event: SyntheticEvent<HTMLInputElement>) => {
|
||||
const checked = event.currentTarget.checked;
|
||||
setIsCommitFilterEnabled(checked);
|
||||
if (checked) {
|
||||
if (inputRef.current !== null) {
|
||||
inputRef.current.focus();
|
||||
}
|
||||
|
|
|
@ -114,19 +114,16 @@ function ProfilerContextController({ children }: Props) {
|
|||
let rootHasProfilingData = false;
|
||||
if (importedProfilingData !== null) {
|
||||
rootHasProfilingData = true;
|
||||
} else if (selectedElementID) {
|
||||
rendererID = store.getRendererIDForElement(
|
||||
((selectedElementID: any): number)
|
||||
);
|
||||
rootID = store.getRootIDForElement(((selectedElementID: any): number));
|
||||
rootHasProfilingData = store.profilingOperations.has(
|
||||
((rootID: any): number)
|
||||
);
|
||||
} else if (selectedElementID !== null) {
|
||||
rendererID = store.getRendererIDForElement(selectedElementID);
|
||||
rootID = store.getRootIDForElement(selectedElementID);
|
||||
rootHasProfilingData =
|
||||
rootID === null ? false : store.profilingOperations.has(rootID);
|
||||
} else if (store.roots.length > 0) {
|
||||
// If no root is selected, assume the first root; many React apps are single root anyway.
|
||||
rootID = store.roots[0];
|
||||
rootHasProfilingData = store.profilingOperations.has(rootID);
|
||||
rendererID = store.getRendererIDForElement(((rootID: any): number));
|
||||
rendererID = store.getRendererIDForElement(rootID);
|
||||
}
|
||||
|
||||
const startProfiling = useCallback(() => store.startProfiling(), [store]);
|
||||
|
|
|
@ -27,15 +27,16 @@ export const calculateSelfDuration = (
|
|||
return 0;
|
||||
}
|
||||
|
||||
let selfDuration = ((actualDurations.get(id): any): number);
|
||||
const node = nodes.get(id);
|
||||
if (node == null) {
|
||||
throw Error(`Could not find node with id "${id}" in commit tree`);
|
||||
}
|
||||
|
||||
let selfDuration = actualDurations.get(id) || 0;
|
||||
|
||||
node.children.forEach(childID => {
|
||||
if (actualDurations.has(childID)) {
|
||||
selfDuration -= ((actualDurations.get(childID): any): number);
|
||||
selfDuration -= actualDurations.get(childID) || 0;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ export function useLocalStorage<T>(
|
|||
|
||||
export function useModalDismissSignal(
|
||||
modalRef: { current: HTMLDivElement | null },
|
||||
dismissCallback: Function
|
||||
dismissCallback: () => void
|
||||
): void {
|
||||
useEffect(() => {
|
||||
if (modalRef.current === null) {
|
||||
|
|
Loading…
Reference in New Issue