Comments (6)
hmm. it wouldn't be a good idea to have that change the global deepmerge that's being required, so it would probably be best if menge.setDefaultOptions returns a copy of merge that can be used instead... something like
const merge = require('deepmerge').setDefaultOptions({
arrayMerge: (dest, source) => source,
});
Otherwise two libraries in the same application that use deepmerge could interfere.
from deepmerge.
Yes, I was planning to make it chainable and return a copy of merge
from deepmerge.
Either way, you still have to do the same thing in your project - which is make a merge.js
file in your shared/common folder for everything in your project to import.
I'm hesitant to add new code to this project, since setting defaults on your own is so easy to do, and there are even different flavors you might want to expose internally.
Able to override options:
import arrayMerge from './somewhere'
import deepmerge from 'deepmerge'
export default (a, b, options) => deepmerge(a, b, Object.assign({ arrayMerge }, options))
Unable to override options:
import arrayMerge from './somewhere'
import deepmerge from 'deepmerge'
export default (a, b) => deepmerge(a, b, { arrayMerge })
Able to merge any number of objects:
import arrayMerge from './somewhere'
import deepmerge from 'deepmerge'
export default (...objects) => deepmerge.all(objects, { arrayMerge })
I think it's better to let everyone decide how they want merge
to be exposed to their project with a line of JS instead of using a baked-in extend function on the library.
from deepmerge.
@TehShrike no, that's incorrect. I am using ES6 and standard require
's, as I imagine the majority of people using Node still do.
As such, all require
's are cached, so I can simply set the defaults once, in my initialisation file, and then whenever I require deepmerge
elsewhere in my application I won't have to worry about the defaults.
E.g.:
init.js
//Set default merge options for deep merge
require('deepmerge').setDefaultOptions({
arrayMerge: (dest, source) => source,
});
anywhere-else.js
const merge = require('deepmerge');
merge(a, b); //Will use the defaults as defined earlier.
The thing is, there must already be defaults (e.g. the default array merge is to concatenate), so I simply want an interface to be able to modify those defaults. The current approach is too cumbersome to manage efficiently across a large codebase.
from deepmerge.
Yes, that's what @macdja38 was addressing - that syntax also affects any other modules that you're requiring. If you're using some gulp library or whatever that uses deepmerge
, you don't want to mess with its default properties.
Your usage of deepmerge
shouldn't affect some webpack library that also happens to use deepmerge
.
Ignore the ES Module syntax in my previous response. The problems are exactly the same even if I use CommonJS in the examples.
from deepmerge.
from deepmerge.
Related Issues (20)
- Is it possible to deepmerge an HTML dom object? HOT 3
- is this library no longer maintained ? HOT 1
- [feature request] more contextual info customMerge HOT 2
- is-mergeable-object is a devDependency HOT 4
- Deepmerge deletes values of ArrayBuffer and replaces to an empty object HOT 4
- How to use one object as target HOT 8
- Deno? HOT 7
- High CPU usage with large object merge HOT 1
- use recursive partial for type definitions HOT 1
- Will we ever see the v5? HOT 4
- When a particular property of the source object is undefined while the target one has a value, the value will be override by undefined HOT 2
- How to delete an element from an array with deepmerge. HOT 1
- How to avoid array concatenation HOT 18
- `is-mergeable-object` is a `devDependency` but used in `index.js` HOT 7
- An error occuren when merge axios config: config.signal.addEventListener is not a function HOT 3
- add ESM, support for module and browser HOT 5
- Possible to remove duplicate objects in arrays? HOT 1
- deepmerge_1.default) is not a function (No Webpack) HOT 4
- A class instance in an array in an object get formed into an object.
- It need filter on merge
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 deepmerge.