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

Kill ReactDoNotBindDeprecated

No one uses this.

Ben Alpert committed Apr 8, 2015 at 15:01 UTC e60a26a6823e273cd9c873f4639cec7f2f086c57
4 files changed +6 -66
src/classic/class/ReactClass.js
+1 -3
@@ -485,13 +485,11 @@ function mixSpecIntoComponent(Constructor, spec) {
485 var isReactClassMethod =
486 ReactClassInterface.hasOwnProperty(name);
487 var isAlreadyDefined = proto.hasOwnProperty(name);
488 - var markedDontBind = property && property.__reactDontBind;
488 var isFunction = typeof property === 'function';
489 var shouldAutoBind =
490 isFunction &&
491 !isReactClassMethod &&
493 - !isAlreadyDefined &&
494 - !markedDontBind;
492 + !isAlreadyDefined;
493
494 if (shouldAutoBind) {
495 if (!proto.__reactAutoBindMap) {
src/classic/class/ReactDoNotBindDeprecated.js deleted
-43
@@ -1,43 +0,0 @@
1 -/**
2 - * Copyright 2013-2015, Facebook, Inc.
3 - * All rights reserved.
4 - *
5 - * This source code is licensed under the BSD-style license found in the
6 - * LICENSE file in the root directory of this source tree. An additional grant
7 - * of patent rights can be found in the PATENTS file in the same directory.
8 - *
9 - * @providesModule ReactDoNotBindDeprecated
10 - */
11 -
12 -'use strict';
13 -
14 -var ReactDoNotBindDeprecated = {
15 - /**
16 - * Marks the method for not being automatically bound on component mounting. A
17 - * couple of reasons you might want to use this:
18 - *
19 - * - Automatically supporting the previous behavior in components that were
20 - * built with previous versions of React.
21 - * - Tuning performance, by avoiding binding on initial render for methods
22 - * that are always invoked while being preceded by `this.`. Such binds are
23 - * unnecessary.
24 - *
25 - * React.createClass({
26 - * handleClick: ReactDoNotBindDeprecated.doNotBind(function() {
27 - * alert(this.setState); // undefined!
28 - * }),
29 - * render: function() {
30 - * return <a onClick={this.handleClick}>Jump</a>;
31 - * }
32 - * });
33 - *
34 - * @param {function} method Method to avoid automatically binding.
35 - * @public
36 - */
37 - doNotBind: function(method) {
38 - method.__reactDontBind = true; // Mutating
39 - return method;
40 - }
41 -};
42 -
43 -module.exports = ReactDoNotBindDeprecated;
src/classic/class/__tests__/ReactBind-test.js
+5 -8
@@ -13,7 +13,6 @@
13
14 var mocks = require('mocks');
15 var React = require('React');
16 -var ReactDoNotBindDeprecated = require('ReactDoNotBindDeprecated');
16 var ReactTestUtils = require('ReactTestUtils');
17 var reactComponentExpect = require('reactComponentExpect');
18
@@ -30,8 +29,8 @@ describe('autobinding', function() {
29 getInitialState: function() {
30 return {something: 'hi'};
31 },
33 - onMouseEnter: ReactDoNotBindDeprecated.doNotBind(mouseDidEnter),
34 - onMouseLeave: ReactDoNotBindDeprecated.doNotBind(mouseDidLeave),
32 + onMouseEnter: mouseDidEnter,
33 + onMouseLeave: mouseDidLeave,
34 onClick: mouseDidClick,
35
36 // auto binding only occurs on top level functions in class defs.
@@ -44,7 +43,7 @@ describe('autobinding', function() {
43 render: function() {
44 return (
45 <div
47 - onMouseOver={this.onMouseEnter.bind(this)}
46 + onMouseOver={this.onMouseEnter}
47 onMouseOut={this.onMouseLeave}
48 onClick={this.onClick}
49 />
@@ -69,8 +68,6 @@ describe('autobinding', function() {
68 badIdea();
69 }).toThrow();
70
72 - expect(mountedInstance1.onMouseEnter).toBe(mountedInstance2.onMouseEnter);
73 - expect(mountedInstance1.onMouseLeave).toBe(mountedInstance2.onMouseLeave);
71 expect(mountedInstance1.onClick).not.toBe(mountedInstance2.onClick);
72
73 ReactTestUtils.Simulate.click(rendered1);
@@ -91,11 +88,11 @@ describe('autobinding', function() {
88
89 ReactTestUtils.Simulate.mouseOut(rendered1);
90 expect(mouseDidLeave.mock.instances.length).toBe(1);
94 - expect(mouseDidLeave.mock.instances[0]).toBe(global);
91 + expect(mouseDidLeave.mock.instances[0]).toBe(mountedInstance1);
92
93 ReactTestUtils.Simulate.mouseOut(rendered2);
94 expect(mouseDidLeave.mock.instances.length).toBe(2);
98 - expect(mouseDidLeave.mock.instances[1]).toBe(global);
95 + expect(mouseDidLeave.mock.instances[1]).toBe(mountedInstance2);
96 });
97
98 it('works with mixins', function() {
src/core/__tests__/ReactCompositeComponent-test.js
-12
@@ -15,7 +15,6 @@ var ChildUpdates;
15 var MorphingComponent;
16 var React;
17 var ReactCurrentOwner;
18 -var ReactDoNotBindDeprecated;
18 var ReactMount;
19 var ReactPropTypes;
20 var ReactServerRendering;
@@ -33,7 +32,6 @@ describe('ReactCompositeComponent', function() {
32 reactComponentExpect = require('reactComponentExpect');
33 React = require('React');
34 ReactCurrentOwner = require('ReactCurrentOwner');
36 - ReactDoNotBindDeprecated = require('ReactDoNotBindDeprecated');
35 ReactPropTypes = require('ReactPropTypes');
36 ReactTestUtils = require('ReactTestUtils');
37 ReactMount = require('ReactMount');
@@ -170,9 +168,6 @@ describe('ReactCompositeComponent', function() {
168 methodAutoBound: function() {
169 return this;
170 },
173 - methodExplicitlyNotBound: ReactDoNotBindDeprecated.doNotBind(function() {
174 - return this;
175 - }),
171 render: function() {
172 return <div></div>;
173 }
@@ -189,9 +184,6 @@ describe('ReactCompositeComponent', function() {
184 expect(function() {
185 mountedInstance.methodAutoBound();
186 }).not.toThrow();
192 - expect(function() {
193 - mountedInstance.methodExplicitlyNotBound();
194 - }).not.toThrow();
187
188 expect(console.error.argsForCall.length).toBe(1);
189 var explicitlyBound = mountedInstance.methodToBeExplicitlyBound.bind(
@@ -199,17 +191,13 @@ describe('ReactCompositeComponent', function() {
191 );
192 expect(console.error.argsForCall.length).toBe(2);
193 var autoBound = mountedInstance.methodAutoBound;
202 - var explicitlyNotBound = mountedInstance.methodExplicitlyNotBound;
194
195 var context = {};
196 expect(explicitlyBound.call(context)).toBe(mountedInstance);
197 expect(autoBound.call(context)).toBe(mountedInstance);
207 - expect(explicitlyNotBound.call(context)).toBe(context);
198
199 expect(explicitlyBound.call(mountedInstance)).toBe(mountedInstance);
200 expect(autoBound.call(mountedInstance)).toBe(mountedInstance);
211 - // This one is the weird one
212 - expect(explicitlyNotBound.call(mountedInstance)).toBe(mountedInstance);
201
202 });
203