From 37d454f7e08942beb9de1f0ff8bbbc855e20f5f0 Mon Sep 17 00:00:00 2001 From: harrisonn Date: Fri, 4 Sep 2020 11:05:59 -0400 Subject: [PATCH] remove unnecessary props from test components --- .../src/components/MyPersistedComponent.js | 149 ++--------------- .../components/MyPersistedComponentNested.js | 151 ++---------------- 2 files changed, 22 insertions(+), 278 deletions(-) diff --git a/@plotly/dash-test-components/src/components/MyPersistedComponent.js b/@plotly/dash-test-components/src/components/MyPersistedComponent.js index eb21e5be36..d64a0bb33e 100644 --- a/@plotly/dash-test-components/src/components/MyPersistedComponent.js +++ b/@plotly/dash-test-components/src/components/MyPersistedComponent.js @@ -1,19 +1,8 @@ import React, {PureComponent} from 'react'; import PropTypes from 'prop-types'; -// simple function to substitute is-numeric for our use case -const isNumber = (n) => { - return !isNaN(parseFloat(n)) && isFinite(n); -} - -// eslint-disable-next-line no-implicit-coercion -const convert = val => (isNumber(val) ? +val : NaN); - const isEquivalent = (v1, v2) => v1 === v2 || (isNaN(v1) && isNaN(v2)); -// using these inline functions instead of ramda -const isNil = val => val == null - const omit = (key, obj) => { const { [key]: omitted, ...rest } = obj; return rest; @@ -22,14 +11,12 @@ const omit = (key, obj) => { /** * Adapted dcc input component for persistence tests. * - * Note that some unnecessary props have been removed. + * Note that unnecessary props have been removed. */ export default class MyPersistedComponent extends PureComponent { constructor(props) { super(props); - this.input = React.createRef(); - this.onChange = this.onChange.bind(this); this.onEvent = this.onEvent.bind(this); this.onKeyPress = this.onKeyPress.bind(this); @@ -39,55 +26,37 @@ export default class MyPersistedComponent extends PureComponent { UNSAFE_componentWillReceiveProps(nextProps) { const {value} = this.input.current; - const valueAsNumber = convert(value); this.setInputValue( - isNil(valueAsNumber) ? value : valueAsNumber, + value, nextProps.value ); - if (this.props.type !== 'number') { - this.setState({value: nextProps.value}); - } + this.setState({value: nextProps.value}); } componentDidMount() { const {value} = this.input.current; - const valueAsNumber = convert(value); this.setInputValue( - isNil(valueAsNumber) ? value : valueAsNumber, + value, this.props.value ); } UNSAFE_componentWillMount() { - if (this.props.type !== 'number') { - this.setState({value: this.props.value}); - } + this.setState({value: this.props.value}) } render() { - const valprops = - this.props.type === 'number' ? {} : {value: this.state.value}; - const {loading_state} = this.props; + const valprops = {value: this.state.value} return ( element, their purposes are different. The