Partially revert React.createDescriptor
We still have some issues to work out when the type argument is a mock.
Sebastian Markbage committed
Jul 25, 2014 at 13:33 UTC
c6b2687bbda0c9d828be51d3d4908adb89d52a09
3 files changed
+16
-4
src/browser/ui/React.js
+8
-2
@@ -46,11 +46,17 @@ var onlyChild = require('onlyChild');
46
47
ReactDefaultInjection.inject();
48
49
-var createDescriptor = ReactDescriptor.createDescriptor;
49
+// TODO: Restore the real create descriptor
50
+// var createDescriptor = ReactDescriptor.createDescriptor;
51
+var createDescriptor = function(type, props, children) {
52
+ // Because of issues with mocks, we temporarily execute the factory function
53
+ var args = Array.prototype.slice.call(arguments, 1);
54
+ return type.apply(null, args);
55
+};
56
var createFactory = ReactDescriptor.createFactory;
57
58
if (__DEV__) {
53
- createDescriptor = ReactDescriptorValidator.createDescriptor;
59
+ // createDescriptor = ReactDescriptorValidator.createDescriptor;
60
createFactory = ReactDescriptorValidator.createFactory;
61
}
62
src/core/ReactDescriptorValidator.js
+6
@@ -229,6 +229,12 @@ var ReactDescriptorValidator = {
229
createDescriptor: function(type, props, children) {
230
var descriptor = ReactDescriptor.createDescriptor.apply(this, arguments);
231
232
+ // The result can be nullish if a mock or a custom function is used.
233
+ // TODO: Drop this when these are no longer allowed as the type argument.
234
+ if (descriptor == null) {
235
+ return descriptor;
236
+ }
237
+
238
for (var i = 2; i < arguments.length; i++) {
239
validateChildKeys(arguments[i], type);
240
}
src/core/__tests__/ReactDescriptor-test.js
+2
-2
@@ -239,12 +239,12 @@ describe('ReactDescriptor', function() {
239
expect(ReactDescriptor.isValidDescriptor(Component)).toEqual(false);
240
});
241
242
- it('warns but allow a plain function to be immediately invoked', function() {
242
+ it('warns but allow a plain function in a factory to be invoked', function() {
243
spyOn(console, 'warn');
244
// This is a temporary helper to allow JSX with plain functions.
245
// This allow you to track down these callers and replace them with regular
246
// function calls.
247
- var factory = ReactDescriptor.createFactory(function (x) {
247
+ var factory = React.createFactory(function (x) {
248
return 21 + x;
249
});
250
expect(factory(21)).toBe(42);