omit-deep
omit-deep copied to clipboard
omitDeep mutates objects
It looks like the omitDeep function is mutating the object I pass in as well as returning it, is this expected behavior or should it be a pure function?
Object.assign()
also mutates objects, but you avoid mutation by shallow cloning before you pass the object to omit-deep (or Object.assign
), by passing an empty object as the first argument:
const obj = Object.assign({} , myObject)`
In this case, if the mutation is happening in omit-deep in a place where you aren't able to get to the code or choose whether or not the object is mutated, I would think that's a bug. I'll take a look as soon as I have a chance.
Makes sense, I was able to avoid this by doing a shallow clone of my object before passing it to omit-deep but ideally there would be a way to decide whether to mutate or not, since the function returns a new object anyways. But that’s up to you of course 🙂
@mattgabor
Actually, the function does not return a new object. Unless you give undefined
as its first parameter. And that is going to change soon.
For anyone having this same issue, I can recommend omit-deep-lodash
. It does not mutate inputs, as evidenced by https://github.com/odynvolk/omit-deep-lodash/pull/16