MCPcopy Create free account
hub / github.com/RubyLouvre/anu / bindAutoBindMethod

Function bindAutoBindMethod

test/react.js:1002–1032  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

1000 * @return {function} The bound method.
1001 */
1002function bindAutoBindMethod(component, method) {
1003 var boundMethod = method.bind(component);
1004 if ("development" !== 'production') {
1005 boundMethod.__reactBoundContext = component;
1006 boundMethod.__reactBoundMethod = method;
1007 boundMethod.__reactBoundArguments = null;
1008 var componentName = component.constructor.displayName;
1009 var _bind = boundMethod.bind;
1010 boundMethod.bind = function (newThis) {
1011 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1012 args[_key - 1] = arguments[_key];
1013 }
1014
1015 // User is trying to bind() an autobound method; we effectively will
1016 // ignore the value of "this" that the user is trying to use, so
1017 // let's warn.
1018 if (newThis !== component && newThis !== null) {
1019 "development" !== 'production' ? warning(false, 'bind(): React component methods may only be bound to the ' + 'component instance. See %s', componentName) : void 0;
1020 } else if (!args.length) {
1021 "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;
1022 return boundMethod;
1023 }
1024 var reboundMethod = _bind.apply(boundMethod, arguments);
1025 reboundMethod.__reactBoundContext = component;
1026 reboundMethod.__reactBoundMethod = method;
1027 reboundMethod.__reactBoundArguments = args;
1028 return reboundMethod;
1029 };
1030 }
1031 return boundMethod;
1032}
1033
1034/**
1035 * Binds all auto-bound methods in a component.

Callers 1

bindAutoBindMethodsFunction · 0.85

Calls 1

warningFunction · 0.70

Tested by

no test coverage detected