GithubHelp home page GithubHelp logo

Comments (7)

rtfeldman avatar rtfeldman commented on July 20, 2024

I dig it! Test duplication is no problem, but from an API perspective I'd prefer if this were an optional boolean passed to merge to enable deep merging.

Would love to see a Pull Request for this. 👍

from seamless-immutable.

crudh avatar crudh commented on July 20, 2024

Ok! Instead of a boolean, what to you think about a mergeWith function or similar that takes a config object first (which the normal merge can use under the covers) so more config can be added later if needed?

obj1.mergeWith({deep: true}, obj2);

I have a use case where I would like to supply a custom merger sometimes, that could fit into this strategy.

But if you don't like it I will do a PR with the boolean.

from seamless-immutable.

RangerMauve avatar RangerMauve commented on July 20, 2024

IMO it's usually nicer to have configs or optional flags as the last argument in a function and not the first.

from seamless-immutable.

crudh avatar crudh commented on July 20, 2024

@RangerMauve I agree in general, but if the With in the function name is for merging with the config I think it is natural if the mandatory config is first. Especially if it is a merge with multiple objects like:

obj1.mergeWith({deep: true}, obj2, obj3, obj4, obj5);

But it doesn't matter much either way. Any thoughts @rtfeldman?

from seamless-immutable.

RangerMauve avatar RangerMauve commented on July 20, 2024

@crudh That's a good point, actually. And it'd work well once rest paramters become mainstream.

from seamless-immutable.

rtfeldman avatar rtfeldman commented on July 20, 2024

Good points all around. My preference is to change the existing merge as follows:

  1. It now always takes exactly one or exactly two arguments.
  2. The first argument works the same as always: you can pass it one object to merge, or an array of them.
  3. The second argument is optional, and is a configuration object that currently supports only {deep: true}

Sound good?

from seamless-immutable.

crudh avatar crudh commented on July 20, 2024

Sounds good to me!

from seamless-immutable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.