@samitouri / QOS-React-2 / commits / 4487831281

Allow `false` as an acceptable renderable type value

`false` is renderable.

Cheng Lou committed Apr 18, 2014 at 12:46 UTC 4487831281a5b48cb6956f60c059ac95f43f1366
2 files changed +11 -24
src/core/ReactPropTypes.js
+5
@@ -260,9 +260,14 @@ function createShapeTypeChecker(shapeTypes) {
260
261 function isRenderable(propValue) {
262 switch(typeof propValue) {
263 + // TODO: this was probably written with the assumption that we're not
264 + // returning `this.props.component` directly from `render`. This is
265 + // currently not supported but we should, to make it consistent.
266 case 'number':
267 case 'string':
268 return true;
269 + case 'boolean':
270 + return !propValue;
271 case 'object':
272 if (Array.isArray(propValue)) {
273 return propValue.every(isRenderable);
src/core/__tests__/ReactPropTypes-test.js
+6 -24
@@ -344,38 +344,20 @@ describe('React Component Types', function() {
344 });
345
346 it('should warn for invalid values', function() {
347 - typeCheckFail(
348 - PropTypes.renderable,
349 - false,
350 - 'Invalid prop `testProp` supplied to `testComponent`, expected a ' +
351 - 'renderable prop.'
352 - );
353 - typeCheckFail(
354 - PropTypes.renderable,
355 - function() {},
356 - 'Invalid prop `testProp` supplied to `testComponent`, expected a ' +
357 - 'renderable prop.'
358 - );
359 - typeCheckFail(
360 - PropTypes.renderable,
361 - {key: function() {}},
362 - 'Invalid prop `testProp` supplied to `testComponent`, expected a ' +
363 - 'renderable prop.'
364 - );
347 + var failMessage = 'Invalid prop `testProp` supplied to `testComponent`, ' +
348 + 'expected a renderable prop.';
349 + typeCheckFail(PropTypes.renderable, true, failMessage);
350 + typeCheckFail(PropTypes.renderable, function() {}, failMessage);
351 + typeCheckFail(PropTypes.renderable, {key: function() {}}, failMessage);
352 });
353
354 it('should not warn for valid values', function() {
368 - // DOM component
355 typeCheckPass(PropTypes.renderable, <div />);
370 - // Custom component
356 + typeCheckPass(PropTypes.renderable, false);
357 typeCheckPass(PropTypes.renderable, <MyComponent />);
372 - // String
358 typeCheckPass(PropTypes.renderable, 'Some string');
374 - // Empty array
359 typeCheckPass(PropTypes.renderable, []);
376 - // Empty object
360 typeCheckPass(PropTypes.renderable, {});
378 - // Array of renderable things
361 typeCheckPass(PropTypes.renderable, [
362 123,
363 'Some string',