mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Cleanup baseIsEqual and baseMerge.
This commit is contained in:
103
lodash.js
103
lodash.js
@@ -1783,17 +1783,14 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!result) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
result = callback ? callback(value, other, key) : undefined;
|
result = callback ? callback(value, other, key) : undefined;
|
||||||
if (!(result = typeof result == 'undefined'
|
result = typeof result == 'undefined'
|
||||||
? baseIsEqual(value[size], othValue, callback, isWhere, stackA, stackB)
|
? baseIsEqual(value[size], othValue, callback, isWhere, stackA, stackB)
|
||||||
: !!result
|
: !!result;
|
||||||
)) {
|
}
|
||||||
break;
|
if (!result) {
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1803,16 +1800,17 @@
|
|||||||
// which, in this case, is more costly
|
// which, in this case, is more costly
|
||||||
baseForIn(other, function(othValue, key, other) {
|
baseForIn(other, function(othValue, key, other) {
|
||||||
if (hasOwnProperty.call(other, key)) {
|
if (hasOwnProperty.call(other, key)) {
|
||||||
|
result = false;
|
||||||
// count the number of properties
|
// count the number of properties
|
||||||
size++;
|
size++;
|
||||||
// deep compare each property value
|
// deep compare each property value
|
||||||
if (!hasOwnProperty.call(value, key)) {
|
if (hasOwnProperty.call(value, key)) {
|
||||||
return (result = false);
|
result = callback ? callback(value, other, key) : undefined;
|
||||||
|
result = typeof result == 'undefined'
|
||||||
|
? baseIsEqual(value[key], othValue, callback, isWhere, stackA, stackB)
|
||||||
|
: !!result;
|
||||||
}
|
}
|
||||||
result = callback ? callback(value, other, key) : undefined;
|
return result;
|
||||||
return (result = typeof result == 'undefined'
|
|
||||||
? baseIsEqual(value[key], othValue, callback, isWhere, stackA, stackB)
|
|
||||||
: !!result);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1845,53 +1843,46 @@
|
|||||||
*/
|
*/
|
||||||
function baseMerge(object, source, callback, stackA, stackB) {
|
function baseMerge(object, source, callback, stackA, stackB) {
|
||||||
(isArray(source) ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
|
(isArray(source) ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
|
||||||
var found,
|
var isArr = srcValue && isArray(srcValue),
|
||||||
isArr,
|
isObj = srcValue && isPlainObject(srcValue),
|
||||||
result = srcValue,
|
|
||||||
value = object[key];
|
value = object[key];
|
||||||
|
|
||||||
if (srcValue && ((isArr = isArray(srcValue)) || isPlainObject(srcValue))) {
|
if (!(isArr || isObj)) {
|
||||||
// avoid merging previously merged cyclic sources
|
result = callback ? callback(value, srcValue, key, object, source) : undefined;
|
||||||
var stackLength = stackA.length;
|
if (typeof result == 'undefined') {
|
||||||
while (stackLength--) {
|
result = srcValue;
|
||||||
if ((found = stackA[stackLength] == srcValue)) {
|
|
||||||
value = stackB[stackLength];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
var isShallow;
|
|
||||||
if (callback) {
|
|
||||||
result = callback(value, srcValue, key, object, source);
|
|
||||||
if ((isShallow = typeof result != 'undefined')) {
|
|
||||||
value = result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!isShallow) {
|
|
||||||
value = isArr
|
|
||||||
? (isArray(value) ? value : [])
|
|
||||||
: (isPlainObject(value) ? value : {});
|
|
||||||
}
|
|
||||||
// add `source` and associated `value` to the stack of traversed objects
|
|
||||||
stackA.push(srcValue);
|
|
||||||
stackB.push(value);
|
|
||||||
|
|
||||||
// recursively merge objects and arrays (susceptible to call stack limits)
|
|
||||||
if (!isShallow) {
|
|
||||||
baseMerge(value, srcValue, callback, stackA, stackB);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (callback) {
|
|
||||||
result = callback(value, srcValue, key, object, source);
|
|
||||||
if (typeof result == 'undefined') {
|
|
||||||
result = srcValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (typeof result != 'undefined') {
|
if (typeof result != 'undefined') {
|
||||||
value = result;
|
value = result;
|
||||||
}
|
}
|
||||||
|
object[key] = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// avoid merging previously merged cyclic sources
|
||||||
|
var length = stackA.length;
|
||||||
|
while (length--) {
|
||||||
|
if (stackA[length] == srcValue) {
|
||||||
|
object[key] = stackB[length];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var result = callback ? callback(value, srcValue, key, object, source) : undefined,
|
||||||
|
isShallow = typeof result != 'undefined';
|
||||||
|
|
||||||
|
if (isShallow) {
|
||||||
|
value = result;
|
||||||
|
} else {
|
||||||
|
value = isArr
|
||||||
|
? (isArray(value) ? value : [])
|
||||||
|
: (isPlainObject(value) ? value : {});
|
||||||
|
}
|
||||||
|
// add `source` and associated `value` to the stack of traversed objects
|
||||||
|
stackA.push(srcValue);
|
||||||
|
stackB.push(value);
|
||||||
|
|
||||||
|
// recursively merge objects and arrays (susceptible to call stack limits)
|
||||||
|
if (!isShallow) {
|
||||||
|
baseMerge(value, srcValue, callback, stackA, stackB);
|
||||||
}
|
}
|
||||||
object[key] = value;
|
object[key] = value;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user