Comments (6)
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
ornull
, 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:
- _.merge (2208 loc)
- merge-options (153 loc) – disclaimer: I'm the author of it
- and many more at npm…
from deep-assign.
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.
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.
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.
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.
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)
- Check "support symbols as targets" fails on ava 0.5.0 HOT 1
- Option to not throw TypeError for null or undefined targets HOT 11
- Overwriting array properties. HOT 4
- Simplify HOT 1
- Deep assigning objects with different property types HOT 1
- Does not work with sealed objects HOT 2
- What is the difference deep assigning with JSON.parse? HOT 1
- Assigning an array shorter than previous one results in merged array HOT 2
- deep assign and functions HOT 2
- Source object get manipulated HOT 3
- it mutates *some* of the sources HOT 5
- Why should this module not be used? HOT 3
- regular expressions are being ignored HOT 2
- Can you add a param(value) which is equal undefined during assigning HOT 1
- Set not being overwritten HOT 3
- Deep-copying arrays HOT 17
- Incorrectly assign object with function as value HOT 2
- Regression in 2.0.0 HOT 11
- test fails: support symbols as targets HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deep-assign.