From eee04b19e1866fdf5fb40298dbbfe7804b691d26 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Mon, 3 Mar 2014 09:39:34 -0800 Subject: [PATCH] Add monitor module for logging instrumentation This adds an instrumentation hook for logging so that we can monitor invalid API usage before we're ready to issue a warning. I took the opportunity to update some console.warns to use the warning module instead. The remaining console.warns will be replaced by the warning module after we've cleaned up the callsites. --- src/browser/dom/DOMPropertyOperations.js | 10 ++--- .../dom/components/LinkedValueUtils.js | 45 +++++++++---------- src/browser/dom/components/ReactDOMOption.js | 15 ++++--- .../dom/components/ReactDOMTextarea.js | 5 ++- src/core/ReactComponent.js | 3 ++ src/core/ReactCompositeComponent.js | 20 ++++++--- src/event/EventPluginHub.js | 2 + src/utils/cloneWithProps.js | 14 +++--- 8 files changed, 65 insertions(+), 49 deletions(-) diff --git a/src/browser/dom/DOMPropertyOperations.js b/src/browser/dom/DOMPropertyOperations.js index 43bdf9c663..ae1e39d632 100644 --- a/src/browser/dom/DOMPropertyOperations.js +++ b/src/browser/dom/DOMPropertyOperations.js @@ -23,6 +23,7 @@ var DOMProperty = require('DOMProperty'); var escapeTextForBrowser = require('escapeTextForBrowser'); var memoizeStringOnly = require('memoizeStringOnly'); +var warning = require('warning'); function shouldIgnoreValue(name, value) { return value == null || @@ -57,11 +58,10 @@ if (__DEV__) { // For now, only warn when we have a suggested correction. This prevents // logging too much when using transferPropsTo. - if (standardName != null) { - console.warn( - 'Unknown DOM property ' + name + '. Did you mean ' + standardName + '?' - ); - } + warning( + standardName == null, + 'Unknown DOM property ' + name + '. Did you mean ' + standardName + '?' + ); }; } diff --git a/src/browser/dom/components/LinkedValueUtils.js b/src/browser/dom/components/LinkedValueUtils.js index ba5c0e618d..3136961cc8 100644 --- a/src/browser/dom/components/LinkedValueUtils.js +++ b/src/browser/dom/components/LinkedValueUtils.js @@ -22,6 +22,7 @@ var ReactPropTypes = require('ReactPropTypes'); var invariant = require('invariant'); +var warning = require('warning'); var hasReadOnlyValue = { 'button': true, @@ -84,33 +85,31 @@ var LinkedValueUtils = { propTypes: { value: function(props, propName, componentName) { if (__DEV__) { - if (props[propName] && - !hasReadOnlyValue[props.type] && - !props.onChange && - !props.readOnly && - !props.disabled) { - console.warn( - 'You provided a `value` prop to a form field without an ' + - '`onChange` handler. This will render a read-only field. If ' + - 'the field should be mutable use `defaultValue`. Otherwise, ' + - 'set either `onChange` or `readOnly`.' - ); - } + warning( + !props[propName] || + hasReadOnlyValue[props.type] || + props.onChange || + props.readOnly || + props.disabled, + 'You provided a `value` prop to a form field without an ' + + '`onChange` handler. This will render a read-only field. If ' + + 'the field should be mutable use `defaultValue`. Otherwise, ' + + 'set either `onChange` or `readOnly`.' + ); } }, checked: function(props, propName, componentName) { if (__DEV__) { - if (props[propName] && - !props.onChange && - !props.readOnly && - !props.disabled) { - console.warn( - 'You provided a `checked` prop to a form field without an ' + - '`onChange` handler. This will render a read-only field. If ' + - 'the field should be mutable use `defaultChecked`. Otherwise, ' + - 'set either `onChange` or `readOnly`.' - ); - } + warning( + !props[propName] || + props.onChange || + props.readOnly || + props.disabled, + 'You provided a `checked` prop to a form field without an ' + + '`onChange` handler. This will render a read-only field. If ' + + 'the field should be mutable use `defaultChecked`. Otherwise, ' + + 'set either `onChange` or `readOnly`.' + ); } }, onChange: ReactPropTypes.func diff --git a/src/browser/dom/components/ReactDOMOption.js b/src/browser/dom/components/ReactDOMOption.js index cf007bf40e..784007b919 100644 --- a/src/browser/dom/components/ReactDOMOption.js +++ b/src/browser/dom/components/ReactDOMOption.js @@ -22,6 +22,8 @@ var ReactBrowserComponentMixin = require('ReactBrowserComponentMixin'); var ReactCompositeComponent = require('ReactCompositeComponent'); var ReactDOM = require('ReactDOM'); +var warning = require('warning'); + // Store a reference to the