mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #637 from cpojer/use-rest-params
Use Rest Parameters where it makes sense
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"browser": true,
|
||||
"esnext": true,
|
||||
|
||||
"bitwise": true,
|
||||
"boss": true,
|
||||
|
||||
@@ -276,7 +276,7 @@ var ReactComponent = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Base constructor for all React component.
|
||||
* Base constructor for all React components.
|
||||
*
|
||||
* Subclasses that override this method should make sure to invoke
|
||||
* `ReactComponent.Mixin.construct.call(this, ...)`.
|
||||
|
||||
@@ -1159,7 +1159,7 @@ var ReactCompositeComponentMixin = {
|
||||
boundMethod.__reactBoundArguments = null;
|
||||
var componentName = component.constructor.displayName;
|
||||
var _bind = boundMethod.bind;
|
||||
boundMethod.bind = function(newThis) {
|
||||
boundMethod.bind = function(newThis, ...args) {
|
||||
// User is trying to bind() an autobound method; we effectively will
|
||||
// ignore the value of "this" that the user is trying to use, so
|
||||
// let's warn.
|
||||
@@ -1168,7 +1168,7 @@ var ReactCompositeComponentMixin = {
|
||||
'bind(): React component methods may only be bound to the ' +
|
||||
'component instance. See ' + componentName
|
||||
);
|
||||
} else if (arguments.length === 1) {
|
||||
} else if (!args.length) {
|
||||
console.warn(
|
||||
'bind(): You are binding a component method to the component. ' +
|
||||
'React does this for you automatically in a high-performance ' +
|
||||
@@ -1179,8 +1179,7 @@ var ReactCompositeComponentMixin = {
|
||||
var reboundMethod = _bind.apply(boundMethod, arguments);
|
||||
reboundMethod.__reactBoundContext = component;
|
||||
reboundMethod.__reactBoundMethod = method;
|
||||
reboundMethod.__reactBoundArguments =
|
||||
Array.prototype.slice.call(arguments, 1);
|
||||
reboundMethod.__reactBoundArguments = args;
|
||||
return reboundMethod;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -187,9 +187,9 @@ if (__DEV__) {
|
||||
|
||||
var fnArgs = _getFnArguments(func);
|
||||
|
||||
return function() {
|
||||
return function(...args) {
|
||||
var timeBeforeFn = performanceNow();
|
||||
var fnReturn = func.apply(this, arguments);
|
||||
var fnReturn = func.apply(this, args);
|
||||
var timeAfterFn = performanceNow();
|
||||
|
||||
/**
|
||||
@@ -197,9 +197,9 @@ if (__DEV__) {
|
||||
* args is also passed to the callback, so if you want to save an
|
||||
* argument in the log, do so in the callback.
|
||||
*/
|
||||
var args = {};
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
args[fnArgs[i]] = arguments[i];
|
||||
var argsObject = {};
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
argsObject[fnArgs[i]] = args[i];
|
||||
}
|
||||
|
||||
var log = {
|
||||
@@ -224,7 +224,7 @@ if (__DEV__) {
|
||||
* - the wrapped method's info object.
|
||||
*/
|
||||
var callback = _getCallback(objName, fnName);
|
||||
callback && callback(this, args, fnReturn, log, info);
|
||||
callback && callback(this, argsObject, fnReturn, log, info);
|
||||
|
||||
log.timing.timeToLog = performanceNow() - timeAfterFn;
|
||||
|
||||
|
||||
Vendored
+3
-7
@@ -29,13 +29,9 @@
|
||||
* @param {string} errorMessage
|
||||
*/
|
||||
|
||||
var ex = function(errorMessage/*, arg1, arg2, ...*/) {
|
||||
var args = Array.prototype.slice.call(arguments).map(function(arg) {
|
||||
return String(arg);
|
||||
});
|
||||
var expectedLength = errorMessage.split('%s').length - 1;
|
||||
|
||||
if (expectedLength !== args.length - 1) {
|
||||
var ex = function(...args) {
|
||||
args = args.map((arg) => String(arg));
|
||||
if (args[0].split('%s').length !== args.length) {
|
||||
// something wrong with the formatting string
|
||||
return ex('ex args number mismatch: %s', JSON.stringify(args));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user