mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Correct fp arg order of assignWith, assignInWith, merge, mergeWith, defaults, and defaultsDeep.
This commit is contained in:
@@ -49,7 +49,7 @@ module.exports = {
|
|||||||
'template', 'trim', 'trimEnd', 'trimStart', 'uniqueId', 'words'
|
'template', 'trim', 'trimEnd', 'trimStart', 'uniqueId', 'words'
|
||||||
],
|
],
|
||||||
2: [
|
2: [
|
||||||
'add', 'after', 'ary', 'assign', 'at', 'before', 'bind', 'bindKey',
|
'add', 'after', 'ary', 'assign', 'assignIn', 'at', 'before', 'bind', 'bindKey',
|
||||||
'chunk', 'cloneDeepWith', 'cloneWith', 'concat', 'countBy', 'curryN',
|
'chunk', 'cloneDeepWith', 'cloneWith', 'concat', 'countBy', 'curryN',
|
||||||
'curryRightN', 'debounce', 'defaults', 'defaultsDeep', 'delay', 'difference',
|
'curryRightN', 'debounce', 'defaults', 'defaultsDeep', 'delay', 'difference',
|
||||||
'drop', 'dropRight', 'dropRightWhile', 'dropWhile', 'endsWith', 'eq',
|
'drop', 'dropRight', 'dropRightWhile', 'dropWhile', 'endsWith', 'eq',
|
||||||
@@ -97,7 +97,10 @@ module.exports = {
|
|||||||
|
|
||||||
/** Used to map method names to rearg configs. */
|
/** Used to map method names to rearg configs. */
|
||||||
'methodRearg': {
|
'methodRearg': {
|
||||||
|
'assignInWith': [1, 2, 0],
|
||||||
|
'assignWith': [1, 2, 0],
|
||||||
'clamp': [2, 0, 1],
|
'clamp': [2, 0, 1],
|
||||||
|
'mergeWith': [1, 2, 0],
|
||||||
'reduce': [2, 0, 1],
|
'reduce': [2, 0, 1],
|
||||||
'reduceRight': [2, 0, 1],
|
'reduceRight': [2, 0, 1],
|
||||||
'set': [2, 0, 1],
|
'set': [2, 0, 1],
|
||||||
@@ -189,8 +192,6 @@ module.exports = {
|
|||||||
'assign': true,
|
'assign': true,
|
||||||
'assignIn': true,
|
'assignIn': true,
|
||||||
'concat': true,
|
'concat': true,
|
||||||
'defaults': true,
|
|
||||||
'defaultsDeep': true,
|
|
||||||
'difference': true,
|
'difference': true,
|
||||||
'matchesProperty': true,
|
'matchesProperty': true,
|
||||||
'merge': true,
|
'merge': true,
|
||||||
|
|||||||
@@ -803,13 +803,13 @@
|
|||||||
deepObject = { 'a': { 'b': 2, 'c': 3 } };
|
deepObject = { 'a': { 'b': 2, 'c': 3 } };
|
||||||
|
|
||||||
QUnit.test('should not mutate values', function(assert) {
|
QUnit.test('should not mutate values', function(assert) {
|
||||||
assert.expect(32);
|
assert.expect(36);
|
||||||
|
|
||||||
function Foo() {}
|
function Foo() {}
|
||||||
Foo.prototype = { 'b': 2 };
|
Foo.prototype = { 'b': 2 };
|
||||||
|
|
||||||
var value = _.clone(object),
|
var value = _.clone(object),
|
||||||
actual = fp.assign({ 'b': 2 }, value);
|
actual = fp.assign(value, { 'b': 2 });
|
||||||
|
|
||||||
assert.deepEqual(value, object, 'fp.assign');
|
assert.deepEqual(value, object, 'fp.assign');
|
||||||
assert.deepEqual(actual, { 'a': 1, 'b': 2 }, 'fp.assign');
|
assert.deepEqual(actual, { 'a': 1, 'b': 2 }, 'fp.assign');
|
||||||
@@ -817,26 +817,40 @@
|
|||||||
value = _.clone(object);
|
value = _.clone(object);
|
||||||
actual = fp.assignWith(function(objValue, srcValue) {
|
actual = fp.assignWith(function(objValue, srcValue) {
|
||||||
return srcValue;
|
return srcValue;
|
||||||
}, { 'b': 2 }, value);
|
}, value, { 'b': 2 });
|
||||||
|
|
||||||
assert.deepEqual(value, object, 'fp.assignWith');
|
assert.deepEqual(value, object, 'fp.assignWith');
|
||||||
assert.deepEqual(actual, { 'a': 1, 'b': 2 }, 'fp.assignWith');
|
assert.deepEqual(actual, { 'a': 1, 'b': 2 }, 'fp.assignWith');
|
||||||
|
|
||||||
value = _.clone(object);
|
value = _.clone(object);
|
||||||
actual = fp.defaults(value, { 'a': 2, 'b': 2 });
|
actual = fp.assignIn(value, new Foo);
|
||||||
|
|
||||||
|
assert.deepEqual(value, object, 'fp.assignIn');
|
||||||
|
assert.deepEqual(actual, { 'a': 1, 'b': 2 }, 'fp.assignIn');
|
||||||
|
|
||||||
|
value = _.clone(object);
|
||||||
|
actual = fp.assignInWith(function(objValue, srcValue) {
|
||||||
|
return srcValue;
|
||||||
|
}, value, new Foo);
|
||||||
|
|
||||||
|
assert.deepEqual(value, object, 'fp.assignInWith');
|
||||||
|
assert.deepEqual(actual, { 'a': 1, 'b': 2 }, 'fp.assignInWith');
|
||||||
|
|
||||||
|
value = _.clone(object);
|
||||||
|
actual = fp.defaults({ 'a': 2, 'b': 2 }, value);
|
||||||
|
|
||||||
assert.deepEqual(value, object, 'fp.defaults');
|
assert.deepEqual(value, object, 'fp.defaults');
|
||||||
assert.deepEqual(actual, { 'a': 1, 'b': 2 }, 'fp.defaults');
|
assert.deepEqual(actual, { 'a': 1, 'b': 2 }, 'fp.defaults');
|
||||||
|
|
||||||
value = _.clone(object);
|
value = _.clone(object);
|
||||||
value.b = { 'c': 1 };
|
value.b = { 'c': 1 };
|
||||||
actual = fp.defaultsDeep(value, { 'b': { 'c': 2, 'd': 2 } });
|
actual = fp.defaultsDeep({ 'b': { 'c': 2, 'd': 2 } }, value);
|
||||||
|
|
||||||
assert.deepEqual(value, { 'a': 1, 'b': { 'c': 1 } } , 'fp.defaultsDeep');
|
assert.deepEqual(value, { 'a': 1, 'b': { 'c': 1 } } , 'fp.defaultsDeep');
|
||||||
assert.deepEqual(actual, { 'a': 1, 'b': { 'c': 1, 'd': 2 } }, 'fp.defaultsDeep');
|
assert.deepEqual(actual, { 'a': 1, 'b': { 'c': 1, 'd': 2 } }, 'fp.defaultsDeep');
|
||||||
|
|
||||||
value = _.clone(object);
|
value = _.clone(object);
|
||||||
actual = fp.extend(new Foo, value);
|
actual = fp.extend(value, new Foo);
|
||||||
|
|
||||||
assert.deepEqual(value, object, 'fp.extend');
|
assert.deepEqual(value, object, 'fp.extend');
|
||||||
assert.deepEqual(actual, { 'a': 1, 'b': 2 }, 'fp.extend');
|
assert.deepEqual(actual, { 'a': 1, 'b': 2 }, 'fp.extend');
|
||||||
@@ -844,7 +858,7 @@
|
|||||||
value = _.clone(object);
|
value = _.clone(object);
|
||||||
actual = fp.extendWith(function(objValue, srcValue) {
|
actual = fp.extendWith(function(objValue, srcValue) {
|
||||||
return srcValue;
|
return srcValue;
|
||||||
}, new Foo, value);
|
}, value, new Foo);
|
||||||
|
|
||||||
assert.deepEqual(value, object, 'fp.extendWith');
|
assert.deepEqual(value, object, 'fp.extendWith');
|
||||||
assert.deepEqual(actual, { 'a': 1, 'b': 2 }, 'fp.extendWith');
|
assert.deepEqual(actual, { 'a': 1, 'b': 2 }, 'fp.extendWith');
|
||||||
@@ -856,7 +870,7 @@
|
|||||||
assert.deepEqual(actual, [1, '*', 3], 'fp.fill');
|
assert.deepEqual(actual, [1, '*', 3], 'fp.fill');
|
||||||
|
|
||||||
value = { 'a': { 'b': 2 } };
|
value = { 'a': { 'b': 2 } };
|
||||||
actual = fp.merge({ 'a': { 'c': 3 } }, value);
|
actual = fp.merge(value, { 'a': { 'c': 3 } });
|
||||||
|
|
||||||
assert.deepEqual(value, { 'a': { 'b': 2 } }, 'fp.merge');
|
assert.deepEqual(value, { 'a': { 'b': 2 } }, 'fp.merge');
|
||||||
assert.deepEqual(actual, { 'a': { 'b': 2, 'c': 3 } }, 'fp.merge');
|
assert.deepEqual(actual, { 'a': { 'b': 2, 'c': 3 } }, 'fp.merge');
|
||||||
@@ -866,7 +880,7 @@
|
|||||||
if (_.isArray(objValue)) {
|
if (_.isArray(objValue)) {
|
||||||
return objValue.concat(srcValue);
|
return objValue.concat(srcValue);
|
||||||
}
|
}
|
||||||
}, { 'a': [2, 3] }, value);
|
}, value, { 'a': [2, 3] });
|
||||||
|
|
||||||
assert.deepEqual(value, { 'a': [1] }, 'fp.mergeWith');
|
assert.deepEqual(value, { 'a': [1] }, 'fp.mergeWith');
|
||||||
assert.deepEqual(actual, { 'a': [1, 2, 3] }, 'fp.mergeWith');
|
assert.deepEqual(actual, { 'a': [1, 2, 3] }, 'fp.mergeWith');
|
||||||
@@ -931,17 +945,18 @@
|
|||||||
var args,
|
var args,
|
||||||
value = _.clone(object);
|
value = _.clone(object);
|
||||||
|
|
||||||
var actual = fp.assignWith(function() {
|
fp.assignWith(function() {
|
||||||
args || (args = _.map(arguments, _.cloneDeep));
|
args || (args = _.map(arguments, _.cloneDeep));
|
||||||
}, { 'b': 2 }, value);
|
}, value, { 'b': 2 });
|
||||||
|
|
||||||
assert.deepEqual(args, [undefined, 2, 'b', { 'a': 1 }, { 'b': 2 }], 'fp.assignWith');
|
assert.deepEqual(args, [undefined, 2, 'b', { 'a': 1 }, { 'b': 2 }], 'fp.assignWith');
|
||||||
|
|
||||||
args = undefined;
|
args = undefined;
|
||||||
value = _.clone(object);
|
value = _.clone(object);
|
||||||
actual = fp.extendWith(function() {
|
|
||||||
|
fp.extendWith(function() {
|
||||||
args || (args = _.map(arguments, _.cloneDeep));
|
args || (args = _.map(arguments, _.cloneDeep));
|
||||||
}, { 'b': 2 }, value);
|
}, value, { 'b': 2 });
|
||||||
|
|
||||||
assert.deepEqual(args, [undefined, 2, 'b', { 'a': 1 }, { 'b': 2 }], 'fp.extendWith');
|
assert.deepEqual(args, [undefined, 2, 'b', { 'a': 1 }, { 'b': 2 }], 'fp.extendWith');
|
||||||
|
|
||||||
@@ -950,16 +965,18 @@
|
|||||||
|
|
||||||
args = undefined;
|
args = undefined;
|
||||||
value = { 'a': [1] };
|
value = { 'a': [1] };
|
||||||
actual = fp.mergeWith(function() {
|
|
||||||
|
fp.mergeWith(function() {
|
||||||
args || (args = _.map(arguments, _.cloneDeep));
|
args || (args = _.map(arguments, _.cloneDeep));
|
||||||
}, { 'a': [2, 3] }, value);
|
}, value, { 'a': [2, 3] });
|
||||||
|
|
||||||
args[5] = _.omitBy(args[5], _.isFunction);
|
args[5] = _.omitBy(args[5], _.isFunction);
|
||||||
assert.deepEqual(args, expected, 'fp.mergeWith');
|
assert.deepEqual(args, expected, 'fp.mergeWith');
|
||||||
|
|
||||||
args = undefined;
|
args = undefined;
|
||||||
value = _.clone(object);
|
value = _.clone(object);
|
||||||
actual = fp.setWith(function() {
|
|
||||||
|
fp.setWith(function() {
|
||||||
args || (args = _.map(arguments, _.cloneDeep));
|
args || (args = _.map(arguments, _.cloneDeep));
|
||||||
}, 'b.c', 2, value);
|
}, 'b.c', 2, value);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user