Comments (2)
👋 Hey Scotty, been a while!
mergerino
treats document.body
as an object and tries to recursively loop through it to merge it, but document.body
doesn't expose its keys so this results in an empty object.
Object.keys(document.body) == []
The easy workaround would be to bypass the merge and just replace the value at that key using a function:
merge({}, {el: () => document.body}) == {el: document.body}
At the very least this should be documented with the workaround, but it's worth considering how it could be handled more nicely.
Maybe a specific check could be added to treat HTML elements as straight assignments rather than trying to merge them, but having a specific check for just HTML elements could be a bit inefficient/odd.
Another idea could be to only attempt to merge objects where the .constructor === Object
, that would exclude anything other than POJOS from being deep merged..
That could be a bit restrictive/opinionated though, it would mean class instances wouldn't get merged in... Then again that might kind of make sense 🤔
Would have to consider performance as well, not sure how cheap .constructor
is to check.
from mergerino.
👋 Hey Daniel!
Yeah the function patch is fine for me, just thought I'd point out the undocumented/unexpected with non-POJOs. FWIW in my non-scientific test the perf hit for this:
else if (val === null || typeof val !== 'object' || val.constructor !== Object || Array.isArray(val)) copy[k] = val
is significant, percentage-wise, but not really meaningful for RW cases, I wouldn't think.
from mergerino.
Related Issues (7)
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 mergerino.