@samitouri / QOS-React-2 / commits / 076047012a

When proxying statics functions, copy properties

Test Plan: jest

Ben Alpert committed Jul 15, 2014 at 15:08 UTC 076047012adf8de9328e582eac35412e6bb808b2
2 files changed +21 -1
src/core/ReactDescriptor.js
+9 -1
@@ -93,7 +93,15 @@ function proxyStaticMethods(target, source) {
93 if (source.hasOwnProperty(key)) {
94 var value = source[key];
95 if (typeof value === 'function') {
96 - target[key] = value.bind(source);
96 + var bound = value.bind(source);
97 + // Copy any properties defined on the function, such as `isRequired` on
98 + // a PropTypes validator. (mergeInto refuses to work on functions.)
99 + for (var k in value) {
100 + if (value.hasOwnProperty(k)) {
101 + bound[k] = value[k];
102 + }
103 + }
104 + target[key] = bound;
105 } else {
106 target[key] = value;
107 }
src/core/__tests__/ReactDescriptor-test.js
+12
@@ -63,4 +63,16 @@ describe('ReactDescriptor', function() {
63 expect(test.foo).toHaveBeenCalledWith(a, b, c);
64 });
65
66 + it('allows the use of PropTypes validators in statics', function() {
67 + var Component = React.createClass({
68 + render: () => null,
69 + statics: {
70 + specialType: React.PropTypes.shape({monkey: React.PropTypes.any})
71 + }
72 + });
73 +
74 + expect(typeof Component.specialType).toBe("function");
75 + expect(typeof Component.specialType.isRequired).toBe("function");
76 + });
77 +
78 });