Skip to content

Commit d26078f

Browse files
committed
🔥 Remove lodash merge
Replaced with Object.assign() Signed-off-by: Jakub Juszczak <[email protected]>
1 parent 6de6963 commit d26078f

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

‎package.json‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@
5656
"release": "webpack --progress --hide-modules --config ./build/webpack.release.js && NODE_ENV=production webpack --progress --hide-modules --config ./build/webpack.release.min.js && webpack --progress --hide-modules --config ./build/webpack.release.full.js && NODE_ENV=production webpack --progress --hide-modules --config ./build/webpack.release.full.min.js",
5757
"prepublish": "yarn run lint && yarn run test && yarn run build"
5858
},
59-
"dependencies": {
60-
"lodash.merge": "^4.6.0"
61-
},
59+
"dependencies": {},
6260
"peerDependencies": {
6361
"chart.js": "^2.6.0",
6462
"vue": "^2.4.2"

‎src/helpers/options.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import merge from 'lodash.merge'
2-
31
export function mergeOptions (obj, src) {
4-
return merge(obj, src)
2+
let mutableObj = Object.assign({}, obj)
3+
return Object.assign(mutableObj, src)
54
}

‎test/unit/specs/helpers/options.spec.js‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,40 @@ describe('mergeOptions.js', () => {
1515
c: 'c'
1616
}
1717

18+
const an = {
19+
a: {
20+
a: 'a'
21+
},
22+
b: {
23+
b: 'a'
24+
}
25+
}
26+
27+
const bn = {
28+
a: {
29+
a: 'a'
30+
},
31+
b: {
32+
b: 'b'
33+
}
34+
}
35+
1836
it('should replace old a and b if a and b are new', () => {
19-
let ab = mergeOptions(a, b)
37+
const ab = mergeOptions(a, b)
2038
expect(ab).to.have.property('a').and.to.equal('b')
2139
expect(ab).to.have.property('b').and.to.equal('b')
2240
})
2341

2442
it('should add c if c is new', () => {
25-
let ac = mergeOptions(a, c)
43+
const ac = mergeOptions(a, c)
2644
expect(ac).to.have.property('a').and.to.equal('a')
2745
expect(ac).to.have.property('b').and.to.equal('a')
2846
expect(ac).to.have.property('c').and.to.equal('c')
2947
})
48+
49+
it('should replace old a and b if a and b are new in nested objects', () => {
50+
const ab = mergeOptions(an, bn)
51+
expect(ab).to.have.deep.property('a.a').and.to.equal('a')
52+
expect(ab).to.have.deep.property('b.b').and.to.equal('b')
53+
})
3054
})

‎yarn.lock‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,10 +3538,6 @@ lodash.keysin@^4.0.0:
35383538
version "4.2.0"
35393539
resolved "https://registry.yarnpkg.com/lodash.keysin/-/lodash.keysin-4.2.0.tgz#8cc3fb35c2d94acc443a1863e02fa40799ea6f28"
35403540

3541-
lodash.merge@^4.6.0:
3542-
version "4.6.0"
3543-
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.0.tgz#69884ba144ac33fe699737a6086deffadd0f89c5"
3544-
35453541
lodash.mergewith@^4.0.0, lodash.mergewith@^4.6.0:
35463542
version "4.6.0"
35473543
resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.0.tgz#150cf0a16791f5903b8891eab154609274bdea55"

0 commit comments

Comments
 (0)