Partially revert React.createDescriptor

We still have some issues to work out when the type argument is a mock.
This commit is contained in:
Sebastian Markbage 2014-07-25 13:33:19 -07:00 committed by Paul O’Shannessy
parent d526456951
commit c6b2687bbd
3 changed files with 16 additions and 4 deletions

View File

@ -46,11 +46,17 @@ var onlyChild = require('onlyChild');
ReactDefaultInjection.inject();
var createDescriptor = ReactDescriptor.createDescriptor;
// TODO: Restore the real create descriptor
// var createDescriptor = ReactDescriptor.createDescriptor;
var createDescriptor = function(type, props, children) {
// Because of issues with mocks, we temporarily execute the factory function
var args = Array.prototype.slice.call(arguments, 1);
return type.apply(null, args);
};
var createFactory = ReactDescriptor.createFactory;
if (__DEV__) {
createDescriptor = ReactDescriptorValidator.createDescriptor;
// createDescriptor = ReactDescriptorValidator.createDescriptor;
createFactory = ReactDescriptorValidator.createFactory;
}

View File

@ -229,6 +229,12 @@ var ReactDescriptorValidator = {
createDescriptor: function(type, props, children) {
var descriptor = ReactDescriptor.createDescriptor.apply(this, arguments);
// The result can be nullish if a mock or a custom function is used.
// TODO: Drop this when these are no longer allowed as the type argument.
if (descriptor == null) {
return descriptor;
}
for (var i = 2; i < arguments.length; i++) {
validateChildKeys(arguments[i], type);
}

View File

@ -239,12 +239,12 @@ describe('ReactDescriptor', function() {
expect(ReactDescriptor.isValidDescriptor(Component)).toEqual(false);
});
it('warns but allow a plain function to be immediately invoked', function() {
it('warns but allow a plain function in a factory to be invoked', function() {
spyOn(console, 'warn');
// This is a temporary helper to allow JSX with plain functions.
// This allow you to track down these callers and replace them with regular
// function calls.
var factory = ReactDescriptor.createFactory(function (x) {
var factory = React.createFactory(function (x) {
return 21 + x;
});
expect(factory(21)).toBe(42);