* 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)
| 4958 | * @return {function} The bound method. |
| 4959 | */ |
| 4960 | function bindAutoBindMethod(component, method) { |
| 4961 | var boundMethod = method.bind(component); |
| 4962 | if ("development" !== 'production') { |
| 4963 | boundMethod.__reactBoundContext = component; |
| 4964 | boundMethod.__reactBoundMethod = method; |
| 4965 | boundMethod.__reactBoundArguments = null; |
| 4966 | var componentName = component.constructor.displayName; |
| 4967 | var _bind = boundMethod.bind; |
| 4968 | boundMethod.bind = function (newThis) { |
| 4969 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { |
| 4970 | args[_key - 1] = arguments[_key]; |
| 4971 | } |
| 4972 | |
| 4973 | // User is trying to bind() an autobound method; we effectively will |
| 4974 | // ignore the value of "this" that the user is trying to use, so |
| 4975 | // let's warn. |
| 4976 | if (newThis !== component && newThis !== null) { |
| 4977 | "development" !== 'production' ? warning(false, 'bind(): React component methods may only be bound to the ' + 'component instance. See %s', componentName) : void 0; |
| 4978 | } else if (!args.length) { |
| 4979 | "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) : void 0; |
| 4980 | return boundMethod; |
| 4981 | } |
| 4982 | var reboundMethod = _bind.apply(boundMethod, arguments); |
| 4983 | reboundMethod.__reactBoundContext = component; |
| 4984 | reboundMethod.__reactBoundMethod = method; |
| 4985 | reboundMethod.__reactBoundArguments = args; |
| 4986 | return reboundMethod; |
| 4987 | }; |
| 4988 | } |
| 4989 | return boundMethod; |
| 4990 | } |
| 4991 | |
| 4992 | /** |
| 4993 | * Binds all auto-bound methods in a component. |
no test coverage detected
searching dependent graphs…