From 13aa8d37e6099afd06c86e7140105f76a0fd95f9 Mon Sep 17 00:00:00 2001 From: Jing Chen Date: Tue, 4 Mar 2014 18:12:13 -0800 Subject: [PATCH] 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. --- src/core/ReactCompositeComponent.js | 2 +- src/core/__tests__/ReactCompositeComponent-test.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/core/ReactCompositeComponent.js b/src/core/ReactCompositeComponent.js index 8543919b0e..efc8f8d2ef 100644 --- a/src/core/ReactCompositeComponent.js +++ b/src/core/ReactCompositeComponent.js @@ -503,7 +503,7 @@ function mixStaticSpecIntoComponent(ConvenienceConstructor, statics) { } for (var name in statics) { var property = statics[name]; - if (!statics.hasOwnProperty(name) || !property) { + if (!statics.hasOwnProperty(name)) { return; } diff --git a/src/core/__tests__/ReactCompositeComponent-test.js b/src/core/__tests__/ReactCompositeComponent-test.js index 82902795a6..d6141e9d48 100644 --- a/src/core/__tests__/ReactCompositeComponent-test.js +++ b/src/core/__tests__/ReactCompositeComponent-test.js @@ -1007,7 +1007,10 @@ describe('ReactCompositeComponent', function() { it('should support statics', function() { var Component = React.createClass({ statics: { - abc: 'def' + abc: 'def', + def: 0, + ghi: null, + jkl: 'mno' }, render: function() { @@ -1018,6 +1021,12 @@ describe('ReactCompositeComponent', function() { ReactTestUtils.renderIntoDocument(instance); expect(instance.constructor.abc).toBe('def'); expect(Component.abc).toBe('def'); + expect(instance.constructor.def).toBe(0); + expect(Component.def).toBe(0); + expect(instance.constructor.ghi).toBe(null); + expect(Component.ghi).toBe(null); + expect(instance.constructor.jkl).toBe('mno'); + expect(Component.jkl).toBe('mno'); }); it('should support statics in mixins', function() {