Giter Site home page Giter Site logo

Comments (6)

schnittstabil avatar schnittstabil commented on June 20, 2024

Unfortunately, this's on purpose. From MDN:

… null and undefined will be ignored.

More precisely, this is due to the ECMAScript® 2015 Language Specification; 19.1.2.1 Object.assign:

5.a If nextSource is undefined or null, let keys be an empty List.

As deep-assign is Recursive Object.assign(), the following happens:

deepAssign({}, {Lat: null,}, {Lat: null,})

// should be similar to
{Lat: deepAssign(<?>, null, null), …}

// which have to be the same as 
{Lat: Object.assign(<?>, null, null), …}

The <?> and the exact recursive semantic is debatable in this case. deep-assign ignores the <?> at the moment – to be at least a bit useful. But in all possible interpretations, the (additional) null values must be ignored because of the spec.

Hence, I believe deep-assign does not match your requirements. There are many merge tools doing this in a different way. Some examples:

from deep-assign.

topgun743 avatar topgun743 commented on June 20, 2024

This is strange behavior suggested by ECMA. Null may b a valid and intended value from source. How come not accept it? Also deepAssign must provide an option to even allow such kind of merging.

from deep-assign.

schnittstabil avatar schnittstabil commented on June 20, 2024

It would be nice to provide options somehow, but the signature is:

deepAssign(target, source, [source, ...])

If you have an idea, which does not conflict with the semantics of Object.assign, then please let us know.

Btw, we must not provide an option – we are free to do; and we are not ECMA of course 😉. deep-assign is fully dedicated being Recursive Object.assign(); therefore we can also create a new project with a different semantic – like, I did with merge-options.

@topgun743 Anyway, does neither _.merge nor merge-options provide you the semantic you need?

from deep-assign.

topgun743 avatar topgun743 commented on June 20, 2024

Looks like I have to turn towards your suggestion. Yes, merge-options looks nice. Will use it now off course. Thanks for suggesting. Great !

from deep-assign.

topgun743 avatar topgun743 commented on June 20, 2024

BTW, you can allow a last object as an option config sort of to deepAssign whose first property can be like

{allowNulls: true, . . . . . . other options}

This way it would be assumed that even null values from source should be forced onto the target. I think it should work.

from deep-assign.

schnittstabil avatar schnittstabil commented on June 20, 2024

Sadly, because of the Object.assign signature/semantics, these options must be also assigned to the result object, which would be undesirable in my opinion.

from deep-assign.

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.