Skip to content

Commit

Permalink
Partially revert React.createDescriptor
Browse files Browse the repository at this point in the history
We still have some issues to work out when the type argument is a mock.
  • Loading branch information
sebmarkbage authored and zpao committed Jul 25, 2014
1 parent d526456 commit c6b2687
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/browser/ui/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions src/core/ReactDescriptorValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/__tests__/ReactDescriptor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c6b2687

Please sign in to comment.