Ensure _.set and _.setWith don't assign a value if it's the same as the destination value.

This commit is contained in:
John-David Dalton
2015-07-26 09:58:33 -07:00
parent 731d5b6872
commit f1597386ef
2 changed files with 57 additions and 38 deletions

View File

@@ -2511,18 +2511,15 @@
while (nested != null && ++index < length) {
var key = path[index];
if (isObject(nested)) {
if (index == lastIndex) {
nested[key] = value;
}
else {
var oldValue = nested[key],
newValue = customizer ? customizer(oldValue, key, nested) : undefined;
var newValue = value;
if (index != lastIndex) {
var oldValue = nested[key];
newValue = customizer ? customizer(oldValue, key, nested) : undefined;
if (newValue === undefined) {
newValue = oldValue == null ? (isIndex(path[index + 1]) ? [] : {}) : oldValue;
}
assignValue(nested, key, newValue);
}
assignValue(nested, key, newValue);
}
nested = nested[key];
}