Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FlowCleanup] InspectorPanel -> Delete PropTypes #21392

Closed
wants to merge 7 commits into from
37 changes: 26 additions & 11 deletions Libraries/Inspector/InspectorPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,24 @@ const Text = require('Text');
const TouchableHighlight = require('TouchableHighlight');
const View = require('View');

class InspectorPanel extends React.Component<$FlowFixMeProps> {
import type {ViewProps} from 'ViewPropTypes';
// Will add this once I get params for the functions
// import type {SyntheticEvent} from 'CoreEventTypes';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid I don't follow these comments. Should they be here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my instructions, I suggested that people could stub out functions types with ?Function and ask for help getting the function signatures in their pull request if they needed help, and looks like you did just that here 👍


type Props = $ReadOnly<{|
...ViewProps,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the render method of InspectorPanel doesn't use any the props from View. So it's unnecessary to spread ViewProps into Props.

devtoolsIsOpen?: ?boolean,
inspecting?: ?boolean,
Copy link
Contributor Author

@dkaushik95 dkaushik95 Sep 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle CI errors indicate that we need to strict type it rather than ?boolean. Do we want strict type checking or nullable type checking? or maybe both. I think this applies to all the boolean values when we are doing:

if(value) then something

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the following work?

  if (value === true) {
    // stuff
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. But these props can be either boolean or undefined. I don't know how to write for both? ?boolean should work, but I get this error:

Sketchy null check on boolean [1] which is potentially false. Perhaps you meant to check for null or undefined [2]?
(`sketchy-null-bool`)`

Copy link
Contributor

@RSNara RSNara Sep 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... There's only one use of <InspectorPanel> in the codebase:

<InspectorPanel
  devtoolsIsOpen={!!this.state.devtoolsAgent}
  inspecting={this.state.inspecting}
  perfing={this.state.perfing}
  setPerfing={this.setPerfing.bind(this)}
  setInspecting={this.setInspecting.bind(this)}
  inspected={this.state.inspected}
  hierarchy={this.state.hierarchy}
  selection={this.state.selection}
  setSelection={this.setSelection.bind(this)}
  touchTargeting={Touchable.TOUCH_TARGET_DEBUG}
  setTouchTargeting={this.setTouchTargeting.bind(this)}
  networking={this.state.networking}
  setNetworking={this.setNetworking.bind(this)}
/>

Lets make the inspecting, setInspecting, perfing, setPerfing, selection, setSelection props non-optional. That should fix our problems.

setInspecting?: ?Function,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear type. Using any, Object, Function, $Subtype<...>, or $Supertype<...> types is not safe! (unclear-type)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

  setInspecting?: ?(val: boolean) => void

Copy link
Contributor

@empyrical empyrical Sep 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: never mind this, missed the custom button component

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@empyrical Hah! You made the same mistake I did. :P

More of a reason to rename Button to InspectorPanelButton.

perfing?: ?boolean,
setPerfing?: ?Function,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear type. Using any, Object, Function, $Subtype<...>, or $Supertype<...> types is not safe! (unclear-type)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

  setPerfing?: ?(val: boolean) => void

touchTargeting?: ?boolean,
setTouchTargeting?: ?Function,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear type. Using any, Object, Function, $Subtype<...>, or $Supertype<...> types is not safe! (unclear-type)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

  setTouchTargeting?: ?(val: boolean) => void

networking?: ?boolean,
setNetworking?: ?Function,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear type. Using any, Object, Function, $Subtype<...>, or $Supertype<...> types is not safe! (unclear-type)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

  setNetworking?: ?(val: boolean) => void

|}>;

class InspectorPanel extends React.Component<Props> {
renderWaiting() {
if (this.props.inspecting) {
return (
Expand Down Expand Up @@ -84,19 +101,17 @@ class InspectorPanel extends React.Component<$FlowFixMeProps> {
}

InspectorPanel.propTypes = {
devtoolsIsOpen: PropTypes.bool,
inspecting: PropTypes.bool,
setInspecting: PropTypes.func,
inspected: PropTypes.object,
perfing: PropTypes.bool,
setPerfing: PropTypes.func,
touchTargeting: PropTypes.bool,
setTouchTargeting: PropTypes.func,
networking: PropTypes.bool,
setNetworking: PropTypes.func,
};

class Button extends React.Component<$FlowFixMeProps> {
type ButtonProps = $ReadOnly<{|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Rename to InspectorPanelButtonProps.

...ViewProps,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear type. Using any, Object, Function, $Subtype<...>, or $Supertype<...> types is not safe! (unclear-type)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to spread ViewProps into ButtonProps. The render method of Button only uses onClick, pressed, and title.

onClick?: ?Function,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RSNara I need a similar params/return type here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. This should also take the same signature:

onClick?: ?(val: boolean) => void

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think about it more, a lot of these types are unnecessarily optional. For example, I think onClick should not be optional, since we assume (in the implementation of this component) that it's a function. Do you mind making these optional properties, that don't need to be optional, non-optional?

pressed?: ?boolean,
title?: ?string,
|}>;

class Button extends React.Component<ButtonProps> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we rename this component to InspectorPanelButton? This current naming is super misleading. When I was reading through this code initially, I thought that the <Button/> used in InspectorPanel was the button component from react-native.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, got confused by that too. I think it would be worth renaming

render() {
return (
<TouchableHighlight
Expand Down