Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef67406

Browse files
sebmarkbagezpao
authored andcommitted
Add simple React.createDescriptor hook
This is the minimal runtime change we need to switch the JSX syntax to resolve to React.createDescriptor(...)
1 parent d0719a5 commit ef67406

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/browser/ui/React.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ var React = {
5353
EventPluginUtils.useTouchEvents = shouldUseTouch;
5454
},
5555
createClass: ReactCompositeComponent.createClass,
56+
createDescriptor: function(type, props, children) {
57+
var args = Array.prototype.slice.call(arguments, 1);
58+
return type.apply(null, args);
59+
},
5660
constructAndRenderComponent: ReactMount.constructAndRenderComponent,
5761
constructAndRenderComponentByID: ReactMount.constructAndRenderComponentByID,
5862
renderComponent: ReactPerf.measure(

src/core/__tests__/ReactDescriptor-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,17 @@ describe('ReactDescriptor', function() {
4545
expect(ReactDescriptor.isValidDescriptor(React.DOM.div)).toEqual(false);
4646
expect(ReactDescriptor.isValidDescriptor(Component)).toEqual(false);
4747
});
48+
49+
it('immediately calls the type passed to createDescriptor', function() {
50+
var a = 1, b = 2, c = 3, d = 4;
51+
52+
var foo = jest.genMockFunction();
53+
foo.mockReturnValue(d);
54+
55+
var result = React.createDescriptor(foo, a, b, c);
56+
57+
expect(result).toBe(d);
58+
expect(foo).toBeCalledWith(a, b, c);
59+
});
60+
4861
});

0 commit comments

Comments
 (0)