@samitouri / QOS-React-2 / commits / 13aa8d37e6

Allow falsy values in statics

We found that the component would break if we set any statics with the value 0. It turns out @chenglou already ran into this with d71736b3ed665d1ffcd0c34a55510ce266a30eb2 but the statics code was copied earlier, and still has this falsy check. Made the same change, updated the unittest.

Jing Chen committed Mar 4, 2014 at 18:12 UTC 13aa8d37e6099afd06c86e7140105f76a0fd95f9
2 files changed +11 -2
src/core/ReactCompositeComponent.js
+1 -1
@@ -503,7 +503,7 @@ function mixStaticSpecIntoComponent(ConvenienceConstructor, statics) {
503 }
504 for (var name in statics) {
505 var property = statics[name];
506 - if (!statics.hasOwnProperty(name) || !property) {
506 + if (!statics.hasOwnProperty(name)) {
507 return;
508 }
509
src/core/__tests__/ReactCompositeComponent-test.js
+10 -1
@@ -1007,7 +1007,10 @@ describe('ReactCompositeComponent', function() {
1007 it('should support statics', function() {
1008 var Component = React.createClass({
1009 statics: {
1010 - abc: 'def'
1010 + abc: 'def',
1011 + def: 0,
1012 + ghi: null,
1013 + jkl: 'mno'
1014 },
1015
1016 render: function() {
@@ -1018,6 +1021,12 @@ describe('ReactCompositeComponent', function() {
1021 ReactTestUtils.renderIntoDocument(instance);
1022 expect(instance.constructor.abc).toBe('def');
1023 expect(Component.abc).toBe('def');
1024 + expect(instance.constructor.def).toBe(0);
1025 + expect(Component.def).toBe(0);
1026 + expect(instance.constructor.ghi).toBe(null);
1027 + expect(Component.ghi).toBe(null);
1028 + expect(instance.constructor.jkl).toBe('mno');
1029 + expect(Component.jkl).toBe('mno');
1030 });
1031
1032 it('should support statics in mixins', function() {