Easier way to merge into existing object #49
Replies: 1 comment 1 reply
-
@RebeccaStevens To me the question arises if the target should also be a source. So when having So when calling The only downside I see is that people might expect the values to only come from the sources, but I think that problem can be solved via docs/jsdoc. |
Beta Was this translation helpful? Give feedback.
-
Sometimes it's useful to not create a new merge result object, but to have an existing object, that is the target of the whole merging process. Right now, I think, I would have to do something like:
If there was a signature like
deepmerge(target, ...sources)
the performance might be better because no intermediate object (result
) needs to be created. Also there would be less code required (no Object.assign). And if we don't want to merge into any existing object we could doconst result = deepmerge({}, myDataObject, newestData));
. Note: The return value is the same object we used as first argument. Without having it returned by deepmerge we would need a bit more code:const result = {}; deepmerge(result, myDataObject, newestData);
Beta Was this translation helpful? Give feedback.
All reactions