Multiple arguments overwrites values in arguments
Using Object.assign with an empty target, only the target is changed, not the inputs/arguments. Usign assign-deep, the inputs also get overwritten. Is this expected behaviour? I did not expect this.
var assignDeep = require("assign-deep")
var o1 = { a: 1, b: 1, c: {a: 1} };
var o2 = { b: 2, c: {a:2} };
var o3 = { c: {a:3} };
console.log(assignDeep({}, o1, o2, o3));
// Expected output: Object {a: 1, b: 2, c: Object {a: 3}}
console.log('o1', o1);
// Expected output: Object {a: 1, b: 1, c: Object {a: 1}}
// Actual output: Object {a: 1, b: 1, c: Object {a: 3}}
I found that also doing a Object.assign({}, o1) before piping into assignDeep didn't help, so maybe I'm in the wrong here. It's a "WAT" moment for me at least :) To solve my use-case I created a method on top that deep copy the input values before piping into assignDeep, and that works for me.
This looks like a bug to me. The code in this area should probably change, but I don't know off the top of my head what is necessary.
I'm not sure when I'll get a chance to look more closely, but PRs are welcome :)
same problem here, this didn't happen with version 0.4.8 or before.
This looks like a bug to me. The code in this area should probably change, but I don't know off the top of my head what is necessary.
I'm not sure when I'll get a chance to look more closely, but PRs are welcome :)
This looks similar to this issue of a related project. I haven't tested it, but I guess, it can be fixed by changing the mentioned line https://github.com/jonschlinkert/assign-deep/blob/ee7ca64849a4c1d9c11ee86c5b8b91337d24c5b4/index.js#L28 to
target[key] = assignSymbols({}, args[i][key]);
in case isObject(args[i][key]).