1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = bindAutoBindMethods;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function bindAutoBindMethod(component, method) {
|
20 | var boundMethod = method.bind(component);
|
21 |
|
22 | boundMethod.__reactBoundContext = component;
|
23 | boundMethod.__reactBoundMethod = method;
|
24 | boundMethod.__reactBoundArguments = null;
|
25 |
|
26 | var componentName = component.constructor.displayName,
|
27 | _bind = boundMethod.bind;
|
28 |
|
29 | boundMethod.bind = function (newThis) {
|
30 | var args = Array.prototype.slice.call(arguments, 1);
|
31 | if (newThis !== component && newThis !== null) {
|
32 | console.warn('bind(): React component methods may only be bound to the ' + 'component instance. See ' + componentName);
|
33 | } else if (!args.length) {
|
34 | console.warn('bind(): You are binding a component method to the component. ' + 'React does this for you automatically in a high-performance ' + 'way, so you can safely remove this call. See ' + componentName);
|
35 | return boundMethod;
|
36 | }
|
37 |
|
38 | var reboundMethod = _bind.apply(boundMethod, arguments);
|
39 | reboundMethod.__reactBoundContext = component;
|
40 | reboundMethod.__reactBoundMethod = method;
|
41 | reboundMethod.__reactBoundArguments = args;
|
42 |
|
43 | return reboundMethod;
|
44 | };
|
45 |
|
46 | return boundMethod;
|
47 | }
|
48 |
|
49 | function bindAutoBindMethods(component) {
|
50 | for (var autoBindKey in component.__reactAutoBindMap) {
|
51 | if (!component.__reactAutoBindMap.hasOwnProperty(autoBindKey)) {
|
52 | return;
|
53 | }
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | if (component.hasOwnProperty(autoBindKey) && component[autoBindKey].__reactBoundContext === component) {
|
59 | continue;
|
60 | }
|
61 |
|
62 | var method = component.__reactAutoBindMap[autoBindKey];
|
63 | component[autoBindKey] = bindAutoBindMethod(component, method);
|
64 | }
|
65 | }; |
\ | No newline at end of file |