@samitouri / QOS-React-2 / commits / decb49a202

Use rest parameters whenever it makes sense.

cpojer committed Dec 4, 2013 at 17:45 UTC decb49a202a74c947c059726ba129f624e74d58d
5 files changed +14 -18
src/.jshintrc
+1
@@ -1,5 +1,6 @@
1 {
2 "browser": true,
3 + "esnext": true,
4
5 "bitwise": true,
6 "boss": true,
src/core/ReactComponent.js
+1 -1
@@ -276,7 +276,7 @@ var ReactComponent = {
276 },
277
278 /**
279 - * Base constructor for all React component.
279 + * Base constructor for all React components.
280 *
281 * Subclasses that override this method should make sure to invoke
282 * `ReactComponent.Mixin.construct.call(this, ...)`.
src/core/ReactCompositeComponent.js
+3 -4
@@ -1156,7 +1156,7 @@ var ReactCompositeComponentMixin = {
1156 boundMethod.__reactBoundArguments = null;
1157 var componentName = component.constructor.displayName;
1158 var _bind = boundMethod.bind;
1159 - boundMethod.bind = function(newThis) {
1159 + boundMethod.bind = function(newThis, ...args) {
1160 // User is trying to bind() an autobound method; we effectively will
1161 // ignore the value of "this" that the user is trying to use, so
1162 // let's warn.
@@ -1165,7 +1165,7 @@ var ReactCompositeComponentMixin = {
1165 'bind(): React component methods may only be bound to the ' +
1166 'component instance. See ' + componentName
1167 );
1168 - } else if (arguments.length === 1) {
1168 + } else if (!args.length) {
1169 console.warn(
1170 'bind(): You are binding a component method to the component. ' +
1171 'React does this for you automatically in a high-performance ' +
@@ -1176,8 +1176,7 @@ var ReactCompositeComponentMixin = {
1176 var reboundMethod = _bind.apply(boundMethod, arguments);
1177 reboundMethod.__reactBoundContext = component;
1178 reboundMethod.__reactBoundMethod = method;
1179 - reboundMethod.__reactBoundArguments =
1180 - Array.prototype.slice.call(arguments, 1);
1179 + reboundMethod.__reactBoundArguments = args;
1180 return reboundMethod;
1181 };
1182 }
src/test/ReactDefaultPerf.js
+6 -6
@@ -187,9 +187,9 @@ if (__DEV__) {
187
188 var fnArgs = _getFnArguments(func);
189
190 - return function() {
190 + return function(...args) {
191 var timeBeforeFn = performanceNow();
192 - var fnReturn = func.apply(this, arguments);
192 + var fnReturn = func.apply(this, args);
193 var timeAfterFn = performanceNow();
194
195 /**
@@ -197,9 +197,9 @@ if (__DEV__) {
197 * args is also passed to the callback, so if you want to save an
198 * argument in the log, do so in the callback.
199 */
200 - var args = {};
201 - for (var i = 0; i < arguments.length; i++) {
202 - args[fnArgs[i]] = arguments[i];
200 + var argsObject = {};
201 + for (var i = 0; i < args.length; i++) {
202 + argsObject[fnArgs[i]] = args[i];
203 }
204
205 var log = {
@@ -224,7 +224,7 @@ if (__DEV__) {
224 * - the wrapped method's info object.
225 */
226 var callback = _getCallback(objName, fnName);
227 - callback && callback(this, args, fnReturn, log, info);
227 + callback && callback(this, argsObject, fnReturn, log, info);
228
229 log.timing.timeToLog = performanceNow() - timeAfterFn;
230
src/vendor/error/ex.js
+3 -7
@@ -29,13 +29,9 @@
29 * @param {string} errorMessage
30 */
31
32 -var ex = function(errorMessage/*, arg1, arg2, ...*/) {
33 - var args = Array.prototype.slice.call(arguments).map(function(arg) {
34 - return String(arg);
35 - });
36 - var expectedLength = errorMessage.split('%s').length - 1;
37 -
38 - if (expectedLength !== args.length - 1) {
32 +var ex = function(...args) {
33 + args = args.map((arg) => String(arg));
34 + if (args[0].split('%s').length !== args.length) {
35 // something wrong with the formatting string
36 return ex('ex args number mismatch: %s', JSON.stringify(args));
37 }