Skip to content

Commit 48575c2

Browse files
committed
chore: resolve conflicts
2 parents 89a4eb2 + 3088ce1 commit 48575c2

File tree

5 files changed

+33
-58
lines changed

5 files changed

+33
-58
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"@rollup/plugin-replace": "^2.3.2",
2323
"@types/estree": "^0.0.42",
2424
"@types/jest": "^24.9.1",
25-
"@types/lodash": "^4.14.149",
2625
"@types/node": "12.12.35",
2726
"@vue/compiler-dom": "^3.0.0-beta.10",
2827
"@vue/compiler-sfc": "^3.0.0-beta.10",

src/utils.ts

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,29 @@ import { GlobalMountOptions } from './types'
22

33
const isString = (val: unknown): val is string => typeof val === 'string'
44

5-
function deepMerge(...objects: object[]) {
6-
const isObject = (obj: any) => obj && typeof obj === 'object'
7-
8-
function deepMergeInner(target: object, source: object) {
9-
Object.keys(source).forEach((key: string) => {
10-
const targetValue = target[key]
11-
const sourceValue = source[key]
12-
13-
if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
14-
target[key] = targetValue.concat(sourceValue)
15-
} else if (isObject(targetValue) && isObject(sourceValue)) {
16-
target[key] = deepMergeInner(
17-
Object.assign({}, targetValue),
18-
sourceValue
19-
)
20-
} else {
21-
target[key] = sourceValue
5+
// Deep merge function, adapted from from https://gist.github.com/ahtcx/0cd94e62691f539160b32ecda18af3d6
6+
// Merge a `source` object to a `target` recursively
7+
const merge = (target: object, source: object) => {
8+
// Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
9+
for (const key of Object.keys(source)) {
10+
if (!target[key]) {
11+
target[key] = source[key]
12+
} else {
13+
if (source[key] instanceof Object) {
14+
Object.assign(source[key], merge(target[key], source[key]))
2215
}
23-
})
24-
25-
return target
26-
}
27-
28-
if (objects.length < 2) {
29-
throw new Error(
30-
'deepMerge: this function expects at least 2 objects to be provided'
31-
)
32-
}
33-
34-
if (objects.some((object) => !isObject(object))) {
35-
throw new Error('deepMerge: all values should be of type "object"')
36-
}
37-
38-
const target = objects.shift()
39-
let source: object
40-
41-
while ((source = objects.shift())) {
42-
deepMergeInner(target, source)
16+
}
4317
}
4418

45-
return target
19+
Object.assign(target || {}, source)
4620
}
4721

4822
function mergeGlobalProperties(
4923
configGlobal: GlobalMountOptions = {},
5024
mountGlobal: GlobalMountOptions = {}
5125
): GlobalMountOptions {
52-
return deepMerge(configGlobal, mountGlobal)
26+
merge(configGlobal, mountGlobal)
27+
return configGlobal
5328
}
5429

5530
export { isString, mergeGlobalProperties }

tests/config.spec.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { h } from 'vue'
2-
31
import { config, mount } from '../src'
42
import Hello from './components/Hello.vue'
53

@@ -23,19 +21,19 @@ describe('config', () => {
2321
}
2422

2523
it('allows setting components globally', () => {
26-
console.log('TODO: Fix this')
27-
const HelloOverride = {
28-
name: 'HelloOverride',
24+
const HelloLocal = {
2925
props: ['msg'],
30-
render() {
31-
return () => h('div', `${this.msg} Hello world override`)
32-
}
26+
template: '<div>{{ msg }}</div>'
3327
}
34-
config.global.components = { Hello: HelloOverride }
35-
const wrapper1 = mount(Component, { props: { msg: 'Wrapper1' } })
36-
const wrapper2 = mount(Component, { props: { msg: 'Wrapper2' } })
37-
expect(wrapper1.text()).toEqual('Wrapper1 Hello world override')
38-
expect(wrapper2.text()).toEqual('Wrapper2 Hello world override')
28+
config.global.components = { Hello: HelloLocal }
29+
const wrapper1 = mount(Component, {
30+
props: { msg: 'Wrapper1 Overwritten' }
31+
})
32+
const wrapper2 = mount(Component, {
33+
props: { msg: 'Wrapper2 Overwritten' }
34+
})
35+
expect(wrapper1.text()).toEqual('Wrapper1 Overwritten')
36+
expect(wrapper2.text()).toEqual('Wrapper2 Overwritten')
3937
})
4038

4139
it('allows overwriting globally set component config on a per mount instance', () => {

tests/mountingOptions/stubs.global.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import ComponentWithoutName from '../components/ComponentWithoutName.vue'
66
import ComponentWithSlots from '../components/ComponentWithSlots.vue'
77

88
describe('mounting options: stubs', () => {
9+
beforeEach(() => {
10+
config.global.stubs = {}
11+
})
12+
13+
afterEach(() => {
14+
config.global.stubs = {}
15+
})
16+
917
it('handles Array syntax', () => {
1018
const Foo = {
1119
name: 'Foo',

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,11 +1127,6 @@
11271127
dependencies:
11281128
jest-diff "^24.3.0"
11291129

1130-
"@types/lodash@^4.14.149":
1131-
version "4.14.150"
1132-
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.150.tgz#649fe44684c3f1fcb6164d943c5a61977e8cf0bd"
1133-
integrity sha512-kMNLM5JBcasgYscD9x/Gvr6lTAv2NVgsKtet/hm93qMyf/D1pt+7jeEZklKJKxMVmXjxbRVQQGfqDSfipYCO6w==
1134-
11351130
"@types/minimatch@*":
11361131
version "3.0.3"
11371132
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"

0 commit comments

Comments
 (0)