mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Add _.placeholder support so wrapped functions may support placeholders.
This commit is contained in:
@@ -156,14 +156,15 @@ function baseConvert(util, name, func) {
|
|||||||
if (wrapper) {
|
if (wrapper) {
|
||||||
return wrapper(func);
|
return wrapper(func);
|
||||||
}
|
}
|
||||||
|
var wrapped = func;
|
||||||
if (mutateMap.array[name]) {
|
if (mutateMap.array[name]) {
|
||||||
func = immutWrap(func, cloneArray);
|
wrapped = immutWrap(func, cloneArray);
|
||||||
}
|
}
|
||||||
else if (mutateMap.object[name]) {
|
else if (mutateMap.object[name]) {
|
||||||
func = immutWrap(func, createCloner(func));
|
wrapped = immutWrap(func, createCloner(func));
|
||||||
}
|
}
|
||||||
else if (mutateMap.set[name]) {
|
else if (mutateMap.set[name]) {
|
||||||
func = immutWrap(func, cloneDeep);
|
wrapped = immutWrap(func, cloneDeep);
|
||||||
}
|
}
|
||||||
var result;
|
var result;
|
||||||
each(mapping.caps, function(cap) {
|
each(mapping.caps, function(cap) {
|
||||||
@@ -174,8 +175,8 @@ function baseConvert(util, name, func) {
|
|||||||
spreadStart = mapping.methodSpread[name];
|
spreadStart = mapping.methodSpread[name];
|
||||||
|
|
||||||
result = spreadStart === undefined
|
result = spreadStart === undefined
|
||||||
? ary(func, cap)
|
? ary(wrapped, cap)
|
||||||
: spread(func, spreadStart);
|
: spread(wrapped, spreadStart);
|
||||||
|
|
||||||
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]);
|
||||||
@@ -196,7 +197,7 @@ function baseConvert(util, name, func) {
|
|||||||
|
|
||||||
result || (result = func);
|
result || (result = func);
|
||||||
if (mapping.placeholder[name]) {
|
if (mapping.placeholder[name]) {
|
||||||
result.placeholder = placeholder;
|
func.placeholder = result.placeholder = placeholder;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -204,8 +205,8 @@ function baseConvert(util, name, func) {
|
|||||||
if (!isLib) {
|
if (!isLib) {
|
||||||
return wrap(name, func);
|
return wrap(name, func);
|
||||||
}
|
}
|
||||||
// Add placeholder alias.
|
// Add placeholder.
|
||||||
_.__ = placeholder;
|
_.placeholder = placeholder;
|
||||||
|
|
||||||
// Iterate over methods for the current ary cap.
|
// Iterate over methods for the current ary cap.
|
||||||
var pairs = [];
|
var pairs = [];
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/** Used to map aliases to their real names. */
|
/** Used to map aliases to their real names. */
|
||||||
exports.aliasToReal = {
|
exports.aliasToReal = {
|
||||||
|
'__': 'placeholder',
|
||||||
'all': 'some',
|
'all': 'some',
|
||||||
'allPass': 'overEvery',
|
'allPass': 'overEvery',
|
||||||
'apply': 'spread',
|
'apply': 'spread',
|
||||||
|
|||||||
24
lodash.js
24
lodash.js
@@ -4122,7 +4122,7 @@
|
|||||||
index = length,
|
index = length,
|
||||||
args = Array(length),
|
args = Array(length),
|
||||||
fn = (this && this !== root && this instanceof wrapper) ? Ctor : func,
|
fn = (this && this !== root && this instanceof wrapper) ? Ctor : func,
|
||||||
placeholder = wrapper.placeholder;
|
placeholder = lodash.placeholder || wrapper.placeholder;
|
||||||
|
|
||||||
while (index--) {
|
while (index--) {
|
||||||
args[index] = arguments[index];
|
args[index] = arguments[index];
|
||||||
@@ -4238,7 +4238,7 @@
|
|||||||
args = composeArgsRight(args, partialsRight, holdersRight);
|
args = composeArgsRight(args, partialsRight, holdersRight);
|
||||||
}
|
}
|
||||||
if (isCurry || isCurryRight) {
|
if (isCurry || isCurryRight) {
|
||||||
var placeholder = wrapper.placeholder,
|
var placeholder = lodash.placeholder || wrapper.placeholder,
|
||||||
argsHolders = replaceHolders(args, placeholder);
|
argsHolders = replaceHolders(args, placeholder);
|
||||||
|
|
||||||
length -= argsHolders.length;
|
length -= argsHolders.length;
|
||||||
@@ -8345,7 +8345,9 @@
|
|||||||
var bind = rest(function(func, thisArg, partials) {
|
var bind = rest(function(func, thisArg, partials) {
|
||||||
var bitmask = BIND_FLAG;
|
var bitmask = BIND_FLAG;
|
||||||
if (partials.length) {
|
if (partials.length) {
|
||||||
var holders = replaceHolders(partials, bind.placeholder);
|
var placeholder = lodash.placeholder || bind.placeholder,
|
||||||
|
holders = replaceHolders(partials, placeholder);
|
||||||
|
|
||||||
bitmask |= PARTIAL_FLAG;
|
bitmask |= PARTIAL_FLAG;
|
||||||
}
|
}
|
||||||
return createWrapper(func, bitmask, thisArg, partials, holders);
|
return createWrapper(func, bitmask, thisArg, partials, holders);
|
||||||
@@ -8398,7 +8400,9 @@
|
|||||||
var bindKey = rest(function(object, key, partials) {
|
var bindKey = rest(function(object, key, partials) {
|
||||||
var bitmask = BIND_FLAG | BIND_KEY_FLAG;
|
var bitmask = BIND_FLAG | BIND_KEY_FLAG;
|
||||||
if (partials.length) {
|
if (partials.length) {
|
||||||
var holders = replaceHolders(partials, bindKey.placeholder);
|
var placeholder = lodash.placeholder || bindKey.placeholder,
|
||||||
|
holders = replaceHolders(partials, placeholder);
|
||||||
|
|
||||||
bitmask |= PARTIAL_FLAG;
|
bitmask |= PARTIAL_FLAG;
|
||||||
}
|
}
|
||||||
return createWrapper(key, bitmask, object, partials, holders);
|
return createWrapper(key, bitmask, object, partials, holders);
|
||||||
@@ -8447,7 +8451,7 @@
|
|||||||
function curry(func, arity, guard) {
|
function curry(func, arity, guard) {
|
||||||
arity = guard ? undefined : arity;
|
arity = guard ? undefined : arity;
|
||||||
var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8491,7 +8495,7 @@
|
|||||||
function curryRight(func, arity, guard) {
|
function curryRight(func, arity, guard) {
|
||||||
arity = guard ? undefined : arity;
|
arity = guard ? undefined : arity;
|
||||||
var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8913,7 +8917,9 @@
|
|||||||
* // => 'hi fred'
|
* // => 'hi fred'
|
||||||
*/
|
*/
|
||||||
var partial = rest(function(func, partials) {
|
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);
|
return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -8949,7 +8955,9 @@
|
|||||||
* // => 'hello fred'
|
* // => 'hello fred'
|
||||||
*/
|
*/
|
||||||
var partialRight = rest(function(func, partials) {
|
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);
|
return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user