When proxying statics functions, copy properties

Test Plan: jest
This commit is contained in:
Ben Alpert
2014-07-15 15:09:16 -07:00
parent e85e5e9952
commit 076047012a
2 changed files with 21 additions and 1 deletions
+9 -1
View File
@@ -93,7 +93,15 @@ function proxyStaticMethods(target, source) {
if (source.hasOwnProperty(key)) {
var value = source[key];
if (typeof value === 'function') {
target[key] = value.bind(source);
var bound = value.bind(source);
// Copy any properties defined on the function, such as `isRequired` on
// a PropTypes validator. (mergeInto refuses to work on functions.)
for (var k in value) {
if (value.hasOwnProperty(k)) {
bound[k] = value[k];
}
}
target[key] = bound;
} else {
target[key] = value;
}
@@ -63,4 +63,16 @@ describe('ReactDescriptor', function() {
expect(test.foo).toHaveBeenCalledWith(a, b, c);
});
it('allows the use of PropTypes validators in statics', function() {
var Component = React.createClass({
render: () => null,
statics: {
specialType: React.PropTypes.shape({monkey: React.PropTypes.any})
}
});
expect(typeof Component.specialType).toBe("function");
expect(typeof Component.specialType.isRequired).toBe("function");
});
});