@samitouri / QOS-React-2 / commits / d71736b3ed

include mixin keys whose values are falsy

the previous behavior is to skip mixin keys whose values are `undefined`, `null`, `''` and (this is a bug) 0. Now, every key is included.

Cheng Lou committed Feb 14, 2014 at 15:36 UTC d71736b3ed665d1ffcd0c34a55510ce266a30eb2
2 files changed +41 -2
src/core/ReactCompositeComponent.js
+2 -2
@@ -445,7 +445,7 @@ function mixSpecIntoComponent(ConvenienceConstructor, spec) {
445 var proto = Constructor.prototype;
446 for (var name in spec) {
447 var property = spec[name];
448 - if (!spec.hasOwnProperty(name) || !property) {
448 + if (!spec.hasOwnProperty(name)) {
449 continue;
450 }
451
@@ -460,7 +460,7 @@ function mixSpecIntoComponent(ConvenienceConstructor, spec) {
460 // 2. Overridden methods (that were mixed in).
461 var isCompositeComponentMethod = name in ReactCompositeComponentInterface;
462 var isInherited = name in proto;
463 - var markedDontBind = property.__reactDontBind;
463 + var markedDontBind = property && property.__reactDontBind;
464 var isFunction = typeof property === 'function';
465 var shouldAutoBind =
466 isFunction &&
src/core/__tests__/ReactCompositeComponent-test.js
+39
@@ -1107,6 +1107,45 @@ describe('ReactCompositeComponent', function() {
1107 );
1108 });
1109
1110 + it('should have bound the mixin methods to the component', function() {
1111 + var mixin = {
1112 + mixinFunc: function() {return this;}
1113 + };
1114 +
1115 + var Component = React.createClass({
1116 + mixins: [mixin],
1117 + componentDidMount: function() {
1118 + expect(this.mixinFunc()).toBe(this);
1119 + },
1120 + render: function() {
1121 + return <span />;
1122 + }
1123 + });
1124 + var instance = <Component />;
1125 + ReactTestUtils.renderIntoDocument(instance);
1126 + });
1127 +
1128 + it('should include the mixin keys in even if their values are falsy',
1129 + function() {
1130 + var mixin = {
1131 + keyWithNullValue: null,
1132 + randomCounter: 0
1133 + };
1134 +
1135 + var Component = React.createClass({
1136 + mixins: [mixin],
1137 + componentDidMount: function() {
1138 + expect(this.randomCounter).toBe(0);
1139 + expect(this.keyWithNullValue).toBeNull();
1140 + },
1141 + render: function() {
1142 + return <span />;
1143 + }
1144 + });
1145 + var instance = <Component />;
1146 + ReactTestUtils.renderIntoDocument(instance);
1147 + });
1148 +
1149 it('should warn if an umounted component is touched', function() {
1150 spyOn(console, 'warn');
1151