* Binds a method to the component. * * @param {object} component Component whose method is going to be bound. * @param {function} method Method to be bound. * @return {function} The bound method.
(component, method)
| 4907 | * @return {function} The bound method. |
| 4908 | */ |
| 4909 | function bindAutoBindMethod(component, method) { |
| 4910 | var boundMethod = method.bind(component); |
| 4911 | if ("development" !== 'production') { |
| 4912 | boundMethod.__reactBoundContext = component; |
| 4913 | boundMethod.__reactBoundMethod = method; |
| 4914 | boundMethod.__reactBoundArguments = null; |
| 4915 | var componentName = component.constructor.displayName; |
| 4916 | var _bind = boundMethod.bind; |
| 4917 | /* eslint-disable block-scoped-var, no-undef */ |
| 4918 | boundMethod.bind = function (newThis) { |
| 4919 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { |
| 4920 | args[_key - 1] = arguments[_key]; |
| 4921 | } |
| 4922 | |
| 4923 | // User is trying to bind() an autobound method; we effectively will |
| 4924 | // ignore the value of "this" that the user is trying to use, so |
| 4925 | // let's warn. |
| 4926 | if (newThis !== component && newThis !== null) { |
| 4927 | "development" !== 'production' ? warning(false, 'bind(): React component methods may only be bound to the ' + 'component instance. See %s', componentName) : undefined; |
| 4928 | } else if (!args.length) { |
| 4929 | "development" !== 'production' ? warning(false, '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 %s', componentName) : undefined; |
| 4930 | return boundMethod; |
| 4931 | } |
| 4932 | var reboundMethod = _bind.apply(boundMethod, arguments); |
| 4933 | reboundMethod.__reactBoundContext = component; |
| 4934 | reboundMethod.__reactBoundMethod = method; |
| 4935 | reboundMethod.__reactBoundArguments = args; |
| 4936 | return reboundMethod; |
| 4937 | /* eslint-enable */ |
| 4938 | }; |
| 4939 | } |
| 4940 | return boundMethod; |
| 4941 | } |
| 4942 | |
| 4943 | /** |
| 4944 | * Binds all auto-bound methods in a component. |
no test coverage detected