I'd like to understand how the immutable methods of lodash/fp work.
Do they deeply clone a collection before changing it or do they implement kind of a structural sharing between the two versions of the object?
I have tried to understand it "from the outside" and I couldn't come to a clear conclusion.
In the first case below, mutating an updated collection doesn't impact the original collection.
However, in the second case, mutating an updated collection does impact the original collection.
var fp = _.noConflict();
var data = { a: { c: {} } };
var updatedData = fp.set(["a", "c", "d"], 5, data);
updatedData.a.c.e = 9;
console.log(updatedData.a.c.e, data.a.c.e);
var data2 = { a: { c: [] } };
var updatedData2 = fp.set(["a", "d"], 5, data2);
updatedData2.a.c[0] = 9;
console.log(updatedData2.a.c[0], data2.a.c[0]);
<script src='https://cdn.jsdelivr.net/g/lodash@4.17(lodash.min.js+lodash.fp.min.js)'></script>
I have also posted the question on Lodash github.