mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 01:38:07 +08:00
Major update breaking changes: - ESLint 7.0.0 (https://eslint.org/docs/user-guide/migrating-to-7.0.0) now includes .eslint.rc.js in its list, which is fine for us. Other changes are not applicable for us. - eslint-plugin-mocha (https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/CHANGELOG.md#700-may-13-2020) drops support for ESLint <7, but this CL updates to 7+. Other changes are not applicable for us. DISABLE_THIRD_PARTY_CHECK=Updating ESLint R=petermarshall@chromium.org Change-Id: I7760e084ef87f73a92f9ea4e075fb4c065047f5a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2534873 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Peter Marshall <petermarshall@chromium.org>
88 lines
2.3 KiB
JavaScript
88 lines
2.3 KiB
JavaScript
import _curry2 from "./internal/_curry2.js";
|
|
import curry from "./curry.js";
|
|
import nAry from "./nAry.js";
|
|
/**
|
|
* Wraps a constructor function inside a curried function that can be called
|
|
* with the same arguments and returns the same type. The arity of the function
|
|
* returned is specified to allow using variadic constructor functions.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.4.0
|
|
* @category Function
|
|
* @sig Number -> (* -> {*}) -> (* -> {*})
|
|
* @param {Number} n The arity of the constructor function.
|
|
* @param {Function} Fn The constructor function to wrap.
|
|
* @return {Function} A wrapped, curried constructor function.
|
|
* @example
|
|
*
|
|
* // Variadic Constructor function
|
|
* function Salad() {
|
|
* this.ingredients = arguments;
|
|
* }
|
|
*
|
|
* Salad.prototype.recipe = function() {
|
|
* const instructions = R.map(ingredient => 'Add a dollop of ' + ingredient, this.ingredients);
|
|
* return R.join('\n', instructions);
|
|
* };
|
|
*
|
|
* const ThreeLayerSalad = R.constructN(3, Salad);
|
|
*
|
|
* // Notice we no longer need the 'new' keyword, and the constructor is curried for 3 arguments.
|
|
* const salad = ThreeLayerSalad('Mayonnaise')('Potato Chips')('Ketchup');
|
|
*
|
|
* console.log(salad.recipe());
|
|
* // Add a dollop of Mayonnaise
|
|
* // Add a dollop of Potato Chips
|
|
* // Add a dollop of Ketchup
|
|
*/
|
|
|
|
var constructN =
|
|
/*#__PURE__*/
|
|
_curry2(function constructN(n, Fn) {
|
|
if (n > 10) {
|
|
throw new Error('Constructor with greater than ten arguments');
|
|
}
|
|
|
|
if (n === 0) {
|
|
return function () {
|
|
return new Fn();
|
|
};
|
|
}
|
|
|
|
return curry(nAry(n, function ($0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
|
|
switch (arguments.length) {
|
|
case 1:
|
|
return new Fn($0);
|
|
|
|
case 2:
|
|
return new Fn($0, $1);
|
|
|
|
case 3:
|
|
return new Fn($0, $1, $2);
|
|
|
|
case 4:
|
|
return new Fn($0, $1, $2, $3);
|
|
|
|
case 5:
|
|
return new Fn($0, $1, $2, $3, $4);
|
|
|
|
case 6:
|
|
return new Fn($0, $1, $2, $3, $4, $5);
|
|
|
|
case 7:
|
|
return new Fn($0, $1, $2, $3, $4, $5, $6);
|
|
|
|
case 8:
|
|
return new Fn($0, $1, $2, $3, $4, $5, $6, $7);
|
|
|
|
case 9:
|
|
return new Fn($0, $1, $2, $3, $4, $5, $6, $7, $8);
|
|
|
|
case 10:
|
|
return new Fn($0, $1, $2, $3, $4, $5, $6, $7, $8, $9);
|
|
}
|
|
}));
|
|
});
|
|
|
|
export default constructN; |