Skip to content

Change ReactPropTypes invariant's to console.warn. #912

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions perf/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"setState-callback.js",
"basic-div.js",
"basic-unmount.js",
"propTypes.js",
"renderComponent-basic.js",
"shouldComponentUpdate.js",
];
Expand Down
85 changes: 85 additions & 0 deletions perf/tests/propTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
if (typeof exports == 'undefined') exports = {};

/*http://benchmarkjs.com/docs#options*/

exports.name = 'propTypes';

var Thing = function() {};
var List;
var ListItem;
var MyReactComponent;
var _rootNode;

exports.setup = function(){
List = React.createClass({
propTypes: {
array: React.PropTypes.array,
bool: React.PropTypes.bool.isRequired,
number: React.PropTypes.number,
string: React.PropTypes.string.isRequired,
func: React.PropTypes.func.isRequired,
renderable: React.PropTypes.renderable.isRequired,
instanceOf: React.PropTypes.instanceOf(Thing).isRequired
},
render: function() {
return React.DOM.ul(null, this.props.children);
}
});

ListItem = React.createClass({
propTypes: {
array: React.PropTypes.array,
bool: React.PropTypes.bool.isRequired,
number: React.PropTypes.number,
string: React.PropTypes.string.isRequired,
func: React.PropTypes.func.isRequired,
renderable: React.PropTypes.renderable.isRequired,
renderable2: React.PropTypes.renderable.isRequired,
instanceOf: React.PropTypes.instanceOf(Thing).isRequired,
component: React.PropTypes.component.isRequired
},
render: function(){
return React.DOM.li(null,
this.props.number + this.props.string + this.props.renderable
);
}
});

MyReactComponent = React.createClass({
render: function() {
return React.DOM.span();
}
});

_rootNode = document.createElement('div');
document.body.appendChild(_rootNode);
};
exports.fn = function(){
var items = [];
for (var i = 0; i < 1000; i++) {
items.push(ListItem({
array: [11, 12, 13, 14, 15, 16, 17, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
bool: false,
number: Math.random(),
string: 'banana banana banana',
func: function() { return 'this is a function'; },
renderable: 'renderable string',
renderable2: [MyReactComponent(), 'a string'],
instanceOf: new Thing,
component: MyReactComponent()
}));
};

React.renderComponent(List({
array: [11, 12, 13, 14, 15, 16, 17, 18, 19, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
bool: false,
number: Math.random(),
string: 'banana banana banana',
func: function() { return 'this is a function'; },
renderable: 'renderable string',
instanceOf: new Thing
}, items), _rootNode);
};
exports.teardown = function(){
React.unmountComponentAtNode(_rootNode);
};
32 changes: 19 additions & 13 deletions src/core/ReactCompositeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,11 +837,13 @@ var ReactCompositeComponentMixin = {
for (var contextName in contextTypes) {
maskedContext[contextName] = context[contextName];
}
this._checkPropTypes(
contextTypes,
maskedContext,
ReactPropTypeLocations.context
);
if (__DEV__) {
this._checkPropTypes(
contextTypes,
maskedContext,
ReactPropTypeLocations.context
);
}
}
return maskedContext;
},
Expand All @@ -861,11 +863,13 @@ var ReactCompositeComponentMixin = {
'use getChildContext().',
displayName
);
this._checkPropTypes(
this.constructor.childContextTypes,
childContext,
ReactPropTypeLocations.childContext
);
if (__DEV__) {
this._checkPropTypes(
this.constructor.childContextTypes,
childContext,
ReactPropTypeLocations.childContext
);
}
for (var name in childContext) {
invariant(
name in this.constructor.childContextTypes,
Expand Down Expand Up @@ -896,9 +900,11 @@ var ReactCompositeComponentMixin = {
props[propName] = defaultProps[propName];
}
}
var propTypes = this.constructor.propTypes;
if (propTypes) {
this._checkPropTypes(propTypes, props, ReactPropTypeLocations.prop);
if (__DEV__) {
var propTypes = this.constructor.propTypes;
if (propTypes) {
this._checkPropTypes(propTypes, props, ReactPropTypeLocations.prop);
}
}
return props;
},
Expand Down
20 changes: 10 additions & 10 deletions src/core/ReactPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
var ReactComponent = require('ReactComponent');
var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');

var warning = require('warning');
var createObjectFrom = require('createObjectFrom');
var invariant = require('invariant');

/**
* Collection of methods that allow declaration and validation of props that are
Expand Down Expand Up @@ -57,7 +57,7 @@ var invariant = require('invariant');
* // An optional string or URI prop named "href".
* href: function(props, propName, componentName) {
* var propValue = props[propName];
* invariant(
* warning(
* propValue == null ||
* typeof propValue === 'string' ||
* propValue instanceof URI,
Expand Down Expand Up @@ -147,7 +147,7 @@ function createPrimitiveTypeChecker(expectedType) {
if (!shouldThrow) {
return isValid;
}
invariant(
warning(
isValid,
'Invalid %s `%s` of type `%s` supplied to `%s`, expected `%s`.',
ReactPropTypeLocationNames[location],
Expand All @@ -169,7 +169,7 @@ function createEnumTypeChecker(expectedValues) {
if (!shouldThrow) {
return isValid;
}
invariant(
warning(
isValid,
'Invalid %s `%s` supplied to `%s`, expected one of %s.',
ReactPropTypeLocationNames[location],
Expand Down Expand Up @@ -199,7 +199,7 @@ function createShapeTypeChecker(shapeTypes) {
if (!shouldThrow) {
return isValid;
}
invariant(
warning(
isValid,
'Invalid %s `%s` of type `%s` supplied to `%s`, expected `object`.',
ReactPropTypeLocationNames[location],
Expand All @@ -219,7 +219,7 @@ function createInstanceTypeChecker(expectedClass) {
if (!shouldThrow) {
return isValid;
}
invariant(
warning(
isValid,
'Invalid %s `%s` supplied to `%s`, expected instance of `%s`.',
ReactPropTypeLocationNames[location],
Expand All @@ -239,7 +239,7 @@ function createRenderableTypeChecker() {
if (!shouldThrow) {
return isValid;
}
invariant(
warning(
isValid,
'Invalid %s `%s` supplied to `%s`, expected a renderable prop.',
ReactPropTypeLocationNames[location],
Expand All @@ -258,7 +258,7 @@ function createComponentTypeChecker() {
if (!shouldThrow) {
return isValid;
}
invariant(
warning(
isValid,
'Invalid %s `%s` supplied to `%s`, expected a React component.',
ReactPropTypeLocationNames[location],
Expand Down Expand Up @@ -288,7 +288,7 @@ function createChainableTypeChecker(validate) {
if (!shouldThrow) {
return isValid;
}
invariant(
warning(
isValid,
'Required %s `%s` was not specified in `%s`.',
ReactPropTypeLocationNames[location],
Expand Down Expand Up @@ -320,7 +320,7 @@ function createUnionTypeChecker(arrayOfValidators) {
break;
}
}
invariant(
warning(
isValid,
'Invalid %s `%s` supplied to `%s`.',
ReactPropTypeLocationNames[location],
Expand Down
Loading