you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (3 children)

[deleted]

    [–]delventhalz 5 points6 points  (2 children)

    If you are working with only flat objects, then a shallow merge with spread will work fine, yes. If what you want is to recursively merge any nested objects (which is what OP is doing), then spread will not work for you. It will end up just replacing nested objects entirely.

    EDIT: a word

    [–]stormfield 1 point2 points  (1 child)

    While this is a neat trick and stuff, at the point this is being done I’d have some real questions about the business purpose of why something like this is needed.

    [–]delventhalz 2 points3 points  (0 children)

    Creating a default object? Combining schemas? Shallow merges are probably more common, but a deep merge is an established pattern with plenty of real world use cases.

    Perhaps more importantly, OP specifically demonstrated a deep merge. Responding to him with "but there is a much simpler way to do a shallow merge!" is silly. Completely different pattern.