Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81152 views
1
/**
2
* Copyright 2013-2014, 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;
44
45