Add _.placeholder support so wrapped functions may support placeholders.

This commit is contained in:
John-David Dalton
2016-02-02 21:08:06 -08:00
parent 7f295dc6e8
commit e404d214aa
3 changed files with 26 additions and 16 deletions

View File

@@ -156,14 +156,15 @@ function baseConvert(util, name, func) {
if (wrapper) {
return wrapper(func);
}
var wrapped = func;
if (mutateMap.array[name]) {
func = immutWrap(func, cloneArray);
wrapped = immutWrap(func, cloneArray);
}
else if (mutateMap.object[name]) {
func = immutWrap(func, createCloner(func));
wrapped = immutWrap(func, createCloner(func));
}
else if (mutateMap.set[name]) {
func = immutWrap(func, cloneDeep);
wrapped = immutWrap(func, cloneDeep);
}
var result;
each(mapping.caps, function(cap) {
@@ -174,8 +175,8 @@ function baseConvert(util, name, func) {
spreadStart = mapping.methodSpread[name];
result = spreadStart === undefined
? ary(func, cap)
: spread(func, spreadStart);
? ary(wrapped, cap)
: spread(wrapped, spreadStart);
if (cap > 1 && !mapping.skipRearg[name]) {
result = rearg(result, mapping.methodRearg[name] || mapping.aryRearg[cap]);
@@ -196,7 +197,7 @@ function baseConvert(util, name, func) {
result || (result = func);
if (mapping.placeholder[name]) {
result.placeholder = placeholder;
func.placeholder = result.placeholder = placeholder;
}
return result;
};
@@ -204,8 +205,8 @@ function baseConvert(util, name, func) {
if (!isLib) {
return wrap(name, func);
}
// Add placeholder alias.
_.__ = placeholder;
// Add placeholder.
_.placeholder = placeholder;
// Iterate over methods for the current ary cap.
var pairs = [];

View File

@@ -1,5 +1,6 @@
/** Used to map aliases to their real names. */
exports.aliasToReal = {
'__': 'placeholder',
'all': 'some',
'allPass': 'overEvery',
'apply': 'spread',

View File

@@ -4122,7 +4122,7 @@
index = length,
args = Array(length),
fn = (this && this !== root && this instanceof wrapper) ? Ctor : func,
placeholder = wrapper.placeholder;
placeholder = lodash.placeholder || wrapper.placeholder;
while (index--) {
args[index] = arguments[index];
@@ -4238,7 +4238,7 @@
args = composeArgsRight(args, partialsRight, holdersRight);
}
if (isCurry || isCurryRight) {
var placeholder = wrapper.placeholder,
var placeholder = lodash.placeholder || wrapper.placeholder,
argsHolders = replaceHolders(args, placeholder);
length -= argsHolders.length;
@@ -8345,7 +8345,9 @@
var bind = rest(function(func, thisArg, partials) {
var bitmask = BIND_FLAG;
if (partials.length) {
var holders = replaceHolders(partials, bind.placeholder);
var placeholder = lodash.placeholder || bind.placeholder,
holders = replaceHolders(partials, placeholder);
bitmask |= PARTIAL_FLAG;
}
return createWrapper(func, bitmask, thisArg, partials, holders);
@@ -8398,7 +8400,9 @@
var bindKey = rest(function(object, key, partials) {
var bitmask = BIND_FLAG | BIND_KEY_FLAG;
if (partials.length) {
var holders = replaceHolders(partials, bindKey.placeholder);
var placeholder = lodash.placeholder || bindKey.placeholder,
holders = replaceHolders(partials, placeholder);
bitmask |= PARTIAL_FLAG;
}
return createWrapper(key, bitmask, object, partials, holders);
@@ -8447,7 +8451,7 @@
function curry(func, arity, guard) {
arity = guard ? undefined : arity;
var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
result.placeholder = curry.placeholder;
result.placeholder = lodash.placeholder || curry.placeholder;
return result;
}
@@ -8491,7 +8495,7 @@
function curryRight(func, arity, guard) {
arity = guard ? undefined : arity;
var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
result.placeholder = curryRight.placeholder;
result.placeholder = lodash.placeholder || curryRight.placeholder;
return result;
}
@@ -8913,7 +8917,9 @@
* // => 'hi fred'
*/
var partial = rest(function(func, partials) {
var holders = replaceHolders(partials, partial.placeholder);
var placeholder = lodash.placeholder || partial.placeholder,
holders = replaceHolders(partials, placeholder);
return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders);
});
@@ -8949,7 +8955,9 @@
* // => 'hello fred'
*/
var partialRight = rest(function(func, partials) {
var holders = replaceHolders(partials, partialRight.placeholder);
var placeholder = lodash.placeholder || partialRight.placeholder,
holders = replaceHolders(partials, placeholder);
return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
});