From 7887f62203c25ab5c092a430e75a5c8aaabba0ae Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 18 Feb 2015 09:56:13 -0700 Subject: [PATCH] Allow removal of debug code in production builds --- src/js/enhanced-switch.jsx | 2 +- src/js/floating-action-button.jsx | 14 ++++++++------ src/js/icon-button.jsx | 15 ++++++++------- src/js/input.jsx | 4 +++- src/js/radio-button-group.jsx | 8 ++++---- src/js/text-field.jsx | 6 +++--- 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/js/enhanced-switch.jsx b/src/js/enhanced-switch.jsx index 7d70e775e197dc..b911e40901678a 100644 --- a/src/js/enhanced-switch.jsx +++ b/src/js/enhanced-switch.jsx @@ -199,7 +199,7 @@ var EnhancedSwitch = React.createClass({ if (!this.props.hasOwnProperty('checked') || this.props.checked == false) { this.setState({switched: newSwitchedValue}); this.refs.checkbox.getDOMNode().checked = newSwitchedValue; - } else { + } else if (process.NODE_ENV !== 'production') { var message = 'Cannot call set method while checked is defined as a property.'; console.error(message); } diff --git a/src/js/floating-action-button.jsx b/src/js/floating-action-button.jsx index fa02ae4e0c2d1c..3ffe5715ff679d 100644 --- a/src/js/floating-action-button.jsx +++ b/src/js/floating-action-button.jsx @@ -29,11 +29,13 @@ var RaisedButton = React.createClass({ }, componentDidMount: function() { - if (this.props.iconClassName && this.props.children) { - var warning = 'You have set both an iconClassName and a child icon. ' + - 'It is recommended you use only one method when adding ' + - 'icons to FloatingActionButtons.'; - console.warn(warning); + if (process.NODE_ENV !== 'production') { + if (this.props.iconClassName && this.props.children) { + var warning = 'You have set both an iconClassName and a child icon. ' + + 'It is recommended you use only one method when adding ' + + 'icons to FloatingActionButtons.'; + console.warn(warning); + } } }, @@ -107,4 +109,4 @@ var RaisedButton = React.createClass({ }); -module.exports = RaisedButton; \ No newline at end of file +module.exports = RaisedButton; diff --git a/src/js/icon-button.jsx b/src/js/icon-button.jsx index f10e52f3ac8e8b..b6cce8cf40a840 100644 --- a/src/js/icon-button.jsx +++ b/src/js/icon-button.jsx @@ -28,12 +28,13 @@ var IconButton = React.createClass({ if (this.props.tooltip) { this._positionTooltip(); } - - if (this.props.iconClassName && this.props.children) { - var warning = 'You have set both an iconClassName and a child icon. ' + - 'It is recommended you use only one method when adding ' + - 'icons to IconButtons.'; - console.warn(warning); + if (process.NODE_ENV !== 'production') { + if (this.props.iconClassName && this.props.children) { + var warning = 'You have set both an iconClassName and a child icon. ' + + 'It is recommended you use only one method when adding ' + + 'icons to IconButtons.'; + console.warn(warning); + } } }, @@ -119,4 +120,4 @@ var IconButton = React.createClass({ }); -module.exports = IconButton; \ No newline at end of file +module.exports = IconButton; diff --git a/src/js/input.jsx b/src/js/input.jsx index 9944cd0b03dc47..35423b469932fa 100644 --- a/src/js/input.jsx +++ b/src/js/input.jsx @@ -35,7 +35,9 @@ var Input = React.createClass({ }, componentDidMount: function() { - console.warn('Input has been deprecated. Please use TextField instead. See http://material-ui.com/#/components/text-fields'); + if (process.NODE_ENV !== 'production') { + console.warn('Input has been deprecated. Please use TextField instead. See http://material-ui.com/#/components/text-fields'); + } }, render: function() { diff --git a/src/js/radio-button-group.jsx b/src/js/radio-button-group.jsx index 4cf31725bae842..aa852bf6438065 100644 --- a/src/js/radio-button-group.jsx +++ b/src/js/radio-button-group.jsx @@ -79,10 +79,10 @@ var RadioButtonGroup = React.createClass({ _updateRadioButtons: function(newSelection) { if (this.state.numberCheckedRadioButtons == 0) { this.setState({selected: newSelection}); - } else { - var message = "Cannot select a different radio button while another radio button " + - "has the 'checked' property set to true."; - console.error(message); + } else if (process.NODE_ENV !== 'production') { + var message = "Cannot select a different radio button while another radio button " + + "has the 'checked' property set to true."; + console.error(message); } }, diff --git a/src/js/text-field.jsx b/src/js/text-field.jsx index ee501f6448406a..fa351726eaaeff 100644 --- a/src/js/text-field.jsx +++ b/src/js/text-field.jsx @@ -158,7 +158,7 @@ var TextField = React.createClass({ }, setErrorText: function(newErrorText) { - if (this.props.hasOwnProperty('errorText')) { + if (process.NODE_ENV !== 'production' && this.props.hasOwnProperty('errorText')) { console.error('Cannot call TextField.setErrorText when errorText is defined as a property.'); } else if (this.isMounted()) { this.setState({errorText: newErrorText}); @@ -166,7 +166,7 @@ var TextField = React.createClass({ }, setValue: function(newValue) { - if (this._isControlled()) { + if (process.NODE_ENV !== 'production' && this._isControlled()) { console.error('Cannot call TextField.setValue when value or valueLink is defined as a property.'); } else if (this.isMounted()) { this._getInputNode().value = newValue; @@ -212,4 +212,4 @@ var TextField = React.createClass({ }); -module.exports = TextField; \ No newline at end of file +module.exports = TextField;