mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Ensure fp _.partial and _.partialRight accept an args param.
This commit is contained in:
@@ -29,7 +29,8 @@ function baseConvert(util, name, func) {
|
|||||||
'isFunction': util.isFunction,
|
'isFunction': util.isFunction,
|
||||||
'iteratee': util.iteratee,
|
'iteratee': util.iteratee,
|
||||||
'keys': util.keys,
|
'keys': util.keys,
|
||||||
'rearg': util.rearg
|
'rearg': util.rearg,
|
||||||
|
'rest': util.rest
|
||||||
};
|
};
|
||||||
|
|
||||||
var ary = _.ary,
|
var ary = _.ary,
|
||||||
@@ -38,7 +39,8 @@ function baseConvert(util, name, func) {
|
|||||||
each = _.forEach,
|
each = _.forEach,
|
||||||
isFunction = _.isFunction,
|
isFunction = _.isFunction,
|
||||||
keys = _.keys,
|
keys = _.keys,
|
||||||
rearg = _.rearg;
|
rearg = _.rearg,
|
||||||
|
spread = _.spread;
|
||||||
|
|
||||||
var baseArity = function(func, n) {
|
var baseArity = function(func, n) {
|
||||||
return n == 2
|
return n == 2
|
||||||
@@ -168,9 +170,13 @@ function baseConvert(util, name, func) {
|
|||||||
each(mapping.aryMethod[cap], function(otherName) {
|
each(mapping.aryMethod[cap], function(otherName) {
|
||||||
if (name == otherName) {
|
if (name == otherName) {
|
||||||
var aryN = !isLib && mapping.iterateeAry[name],
|
var aryN = !isLib && mapping.iterateeAry[name],
|
||||||
reargIndexes = mapping.iterateeRearg[name];
|
reargIndexes = mapping.iterateeRearg[name],
|
||||||
|
spreadStart = mapping.methodSpread[name];
|
||||||
|
|
||||||
|
result = spreadStart === undefined
|
||||||
|
? ary(func, cap)
|
||||||
|
: spread(func, spreadStart);
|
||||||
|
|
||||||
result = ary(func, cap);
|
|
||||||
if (cap > 1 && !mapping.skipRearg[name]) {
|
if (cap > 1 && !mapping.skipRearg[name]) {
|
||||||
result = rearg(result, mapping.methodRearg[name] || mapping.aryRearg[cap]);
|
result = rearg(result, mapping.methodRearg[name] || mapping.aryRearg[cap]);
|
||||||
}
|
}
|
||||||
@@ -198,6 +204,9 @@ function baseConvert(util, name, func) {
|
|||||||
if (!isLib) {
|
if (!isLib) {
|
||||||
return wrap(name, func);
|
return wrap(name, func);
|
||||||
}
|
}
|
||||||
|
// Add placeholder alias.
|
||||||
|
_.__ = placeholder;
|
||||||
|
|
||||||
// Iterate over methods for the current ary cap.
|
// Iterate over methods for the current ary cap.
|
||||||
var pairs = [];
|
var pairs = [];
|
||||||
each(mapping.caps, function(cap) {
|
each(mapping.caps, function(cap) {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ exports.aryMethod = {
|
|||||||
'attempt', 'ceil', 'create', 'curry', 'curryRight', 'floor', 'fromPairs',
|
'attempt', 'ceil', 'create', 'curry', 'curryRight', 'floor', 'fromPairs',
|
||||||
'invert', 'iteratee', 'memoize', 'method', 'methodOf', 'mixin', 'over',
|
'invert', 'iteratee', 'memoize', 'method', 'methodOf', 'mixin', 'over',
|
||||||
'overEvery', 'overSome', 'rest', 'reverse', 'round', 'runInContext',
|
'overEvery', 'overSome', 'rest', 'reverse', 'round', 'runInContext',
|
||||||
'template', 'trim', 'trimEnd', 'trimStart', 'uniqueId', 'words'
|
'spread', 'template', 'trim', 'trimEnd', 'trimStart', 'uniqueId', 'words'
|
||||||
],
|
],
|
||||||
2: [
|
2: [
|
||||||
'add', 'after', 'ary', 'assign', 'assignIn', 'at', 'before', 'bind', 'bindKey',
|
'add', 'after', 'ary', 'assign', 'assignIn', 'at', 'before', 'bind', 'bindKey',
|
||||||
@@ -147,6 +147,12 @@ exports.methodRearg = {
|
|||||||
'transform': [2, 0, 1]
|
'transform': [2, 0, 1]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Used to map method names to spread configs. */
|
||||||
|
exports.methodSpread = {
|
||||||
|
'partial': 1,
|
||||||
|
'partialRight': 1
|
||||||
|
};
|
||||||
|
|
||||||
/** Used to identify methods which mutate arrays or objects. */
|
/** Used to identify methods which mutate arrays or objects. */
|
||||||
exports.mutate = {
|
exports.mutate = {
|
||||||
'array': {
|
'array': {
|
||||||
|
|||||||
@@ -6,5 +6,6 @@ module.exports = {
|
|||||||
'isFunction': require('../isFunction'),
|
'isFunction': require('../isFunction'),
|
||||||
'iteratee': require('../iteratee'),
|
'iteratee': require('../iteratee'),
|
||||||
'keys': require('../_baseKeys'),
|
'keys': require('../_baseKeys'),
|
||||||
'rearg': require('../rearg')
|
'rearg': require('../rearg'),
|
||||||
|
'spread': require('../spread')
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -161,7 +161,7 @@
|
|||||||
|
|
||||||
var funcMethods = [
|
var funcMethods = [
|
||||||
'after', 'ary', 'before', 'bind', 'bindKey', 'curryN', 'debounce', 'delay',
|
'after', 'ary', 'before', 'bind', 'bindKey', 'curryN', 'debounce', 'delay',
|
||||||
'overArgs', 'rearg', 'throttle', 'wrap'
|
'overArgs', 'partial', 'partialRight', 'rearg', 'throttle', 'wrap'
|
||||||
];
|
];
|
||||||
|
|
||||||
var exceptions = _.difference(funcMethods.concat('matchesProperty'), ['cloneDeepWith', 'cloneWith', 'delay']),
|
var exceptions = _.difference(funcMethods.concat('matchesProperty'), ['cloneDeepWith', 'cloneWith', 'delay']),
|
||||||
@@ -514,9 +514,10 @@
|
|||||||
var func = fp[methodName];
|
var func = fp[methodName];
|
||||||
|
|
||||||
QUnit.test('`_.' + methodName + '` should have a `placeholder` property', function(assert) {
|
QUnit.test('`_.' + methodName + '` should have a `placeholder` property', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(2);
|
||||||
|
|
||||||
assert.ok(_.isObject(func.placeholder));
|
assert.ok(_.isObject(func.placeholder));
|
||||||
|
assert.strictEqual(func.placeholder, fp.__);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -865,6 +866,27 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
QUnit.module('fp.partial and fp.partialRight');
|
||||||
|
|
||||||
|
_.each(['partial', 'partialRight'], function(methodName) {
|
||||||
|
var func = fp[methodName],
|
||||||
|
isPartial = methodName == 'partial';
|
||||||
|
|
||||||
|
QUnit.test('`_.' + methodName + '` should accept an `args` param', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
var expected = isPartial ? [1, 2, 3] : [0, 1, 2];
|
||||||
|
|
||||||
|
var actual = func(function(a, b, c) {
|
||||||
|
return [a, b, c];
|
||||||
|
})([1, 2])(isPartial ? 3 : 0);
|
||||||
|
|
||||||
|
assert.deepEqual(actual, expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('fp.random');
|
QUnit.module('fp.random');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user