mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Ensure bailouts of lazy chaining will fallback appropriately.
This commit is contained in:
@@ -1168,7 +1168,7 @@
|
|||||||
function lazyValue() {
|
function lazyValue() {
|
||||||
var array = this.__wrapped__.value();
|
var array = this.__wrapped__.value();
|
||||||
if (!isArray(array)) {
|
if (!isArray(array)) {
|
||||||
return baseWrapperValue(array, this.__actions__);
|
return baseWrapperValue(array, this.__actions__ || []);
|
||||||
}
|
}
|
||||||
var dir = this.__dir__,
|
var dir = this.__dir__,
|
||||||
isRight = dir < 0,
|
isRight = dir < 0,
|
||||||
@@ -6169,15 +6169,20 @@
|
|||||||
*/
|
*/
|
||||||
function wrapperReverse() {
|
function wrapperReverse() {
|
||||||
var value = this.__wrapped__;
|
var value = this.__wrapped__;
|
||||||
|
|
||||||
|
var interceptor = function(value) {
|
||||||
|
return value.reverse();
|
||||||
|
};
|
||||||
if (value instanceof LazyWrapper) {
|
if (value instanceof LazyWrapper) {
|
||||||
if (this.__actions__.length) {
|
if (this.__actions__.length) {
|
||||||
value = new LazyWrapper(this);
|
value = new LazyWrapper(this);
|
||||||
}
|
}
|
||||||
return new LodashWrapper(value.reverse(), this.__chain__);
|
value = value.reverse();
|
||||||
|
var actions = value.__actions__ || (value.__actions__ = []);
|
||||||
|
actions.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash });
|
||||||
|
return new LodashWrapper(value, this.__chain__);
|
||||||
}
|
}
|
||||||
return this.thru(function(value) {
|
return this.thru(interceptor);
|
||||||
return value.reverse();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12283,15 +12288,15 @@
|
|||||||
|
|
||||||
// Add `LazyWrapper` methods to `lodash.prototype`.
|
// Add `LazyWrapper` methods to `lodash.prototype`.
|
||||||
baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
||||||
var lodashFunc = lodash[methodName];
|
var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
|
||||||
|
retUnwrapped = /^(?:first|last)$/.test(methodName),
|
||||||
|
lodashFunc = lodash[retUnwrapped ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName];
|
||||||
|
|
||||||
if (!lodashFunc) {
|
if (!lodashFunc) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
|
|
||||||
retUnwrapped = /^(?:first|last)$/.test(methodName);
|
|
||||||
|
|
||||||
lodash.prototype[methodName] = function() {
|
lodash.prototype[methodName] = function() {
|
||||||
var args = arguments,
|
var args = retUnwrapped ? [1] : arguments,
|
||||||
chainAll = this.__chain__,
|
chainAll = this.__chain__,
|
||||||
value = this.__wrapped__,
|
value = this.__wrapped__,
|
||||||
isHybrid = !!this.__actions__.length,
|
isHybrid = !!this.__actions__.length,
|
||||||
@@ -12299,24 +12304,27 @@
|
|||||||
iteratee = args[0],
|
iteratee = args[0],
|
||||||
useLazy = isLazy || isArray(value);
|
useLazy = isLazy || isArray(value);
|
||||||
|
|
||||||
|
var interceptor = function(value) {
|
||||||
|
return lodashFunc.apply(lodash, arrayPush([value], args));
|
||||||
|
};
|
||||||
if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
|
if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
|
||||||
// avoid lazy use if the iteratee has a "length" value other than `1`
|
// Avoid lazy use if the iteratee has a "length" value other than `1`.
|
||||||
isLazy = useLazy = false;
|
isLazy = useLazy = false;
|
||||||
}
|
}
|
||||||
var onlyLazy = isLazy && !isHybrid;
|
var onlyLazy = isLazy && !isHybrid;
|
||||||
if (retUnwrapped && !chainAll) {
|
if (retUnwrapped && !chainAll) {
|
||||||
return onlyLazy
|
if (onlyLazy) {
|
||||||
? func.call(value)
|
value = value.clone();
|
||||||
: lodashFunc.call(lodash, this.value());
|
var actions = value.__actions__ || (value.__actions__ = []);
|
||||||
|
actions.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash });
|
||||||
|
return func.call(value);
|
||||||
|
}
|
||||||
|
return lodashFunc.call(lodash, this.value())[0];
|
||||||
}
|
}
|
||||||
var interceptor = function(value) {
|
|
||||||
return lodashFunc.apply(lodash, arrayPush([value], args));
|
|
||||||
};
|
|
||||||
if (useLazy) {
|
if (useLazy) {
|
||||||
var wrapper = onlyLazy ? value : new LazyWrapper(this),
|
value = onlyLazy ? value : new LazyWrapper(this);
|
||||||
result = func.apply(wrapper, args);
|
var result = func.apply(value, args);
|
||||||
|
if (!retUnwrapped) {
|
||||||
if (!retUnwrapped && (isHybrid || result.__actions__)) {
|
|
||||||
var actions = result.__actions__ || (result.__actions__ = []);
|
var actions = result.__actions__ || (result.__actions__ = []);
|
||||||
actions.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash });
|
actions.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user