mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-11 11:45:15 +08:00
fix(core): mergeDeep now can merge nulls (#4088)
This commit is contained in:
parent
31f3746491
commit
fe78faab55
@ -5,14 +5,10 @@ export function mergeDeep(target: Record<string, any>, source: Record<string, an
|
|||||||
|
|
||||||
if (isPlainObject(target) && isPlainObject(source)) {
|
if (isPlainObject(target) && isPlainObject(source)) {
|
||||||
Object.keys(source).forEach(key => {
|
Object.keys(source).forEach(key => {
|
||||||
if (isPlainObject(source[key])) {
|
if (isPlainObject(source[key]) && isPlainObject(target[key])) {
|
||||||
if (!(key in target)) {
|
output[key] = mergeDeep(target[key], source[key])
|
||||||
Object.assign(output, { [key]: source[key] })
|
|
||||||
} else {
|
|
||||||
output[key] = mergeDeep(target[key], source[key])
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Object.assign(output, { [key]: source[key] })
|
output[key] = source[key]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,21 @@ describe('mergeDeep', () => {
|
|||||||
expect(merged).to.deep.eq(result)
|
expect(merged).to.deep.eq(result)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should merge when source has null value', () => {
|
||||||
|
const one = {
|
||||||
|
a: null,
|
||||||
|
}
|
||||||
|
const two = {
|
||||||
|
a: { c: 3 },
|
||||||
|
}
|
||||||
|
const result = {
|
||||||
|
a: { c: 3 },
|
||||||
|
}
|
||||||
|
const merged = mergeDeep(one, two)
|
||||||
|
|
||||||
|
expect(merged).to.deep.eq(result)
|
||||||
|
})
|
||||||
|
|
||||||
it('should not merge array', () => {
|
it('should not merge array', () => {
|
||||||
const one = {
|
const one = {
|
||||||
a: [1],
|
a: [1],
|
||||||
@ -34,6 +49,36 @@ describe('mergeDeep', () => {
|
|||||||
expect(merged).to.deep.eq(result)
|
expect(merged).to.deep.eq(result)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should merge when source has null value', () => {
|
||||||
|
const one = {
|
||||||
|
a: null,
|
||||||
|
}
|
||||||
|
const two = {
|
||||||
|
a: { c: 3 },
|
||||||
|
}
|
||||||
|
const result = {
|
||||||
|
a: { c: 3 },
|
||||||
|
}
|
||||||
|
const merged = mergeDeep(one, two)
|
||||||
|
|
||||||
|
expect(merged).to.deep.eq(result)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should allow nulling a value', () => {
|
||||||
|
const one = {
|
||||||
|
a: { c: 3 },
|
||||||
|
}
|
||||||
|
const two = {
|
||||||
|
a: { c: null },
|
||||||
|
}
|
||||||
|
const result = {
|
||||||
|
a: { c: null },
|
||||||
|
}
|
||||||
|
const merged = mergeDeep(one, two)
|
||||||
|
|
||||||
|
expect(merged).to.deep.eq(result)
|
||||||
|
})
|
||||||
|
|
||||||
it('should merge deep', () => {
|
it('should merge deep', () => {
|
||||||
const one = {
|
const one = {
|
||||||
a: 1,
|
a: 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user