fix: fix merging options on configure for multiple extension instances

This commit is contained in:
Philipp Kühn
2021-06-03 13:13:43 +02:00
parent c54a9350fb
commit d037c5656a
4 changed files with 19 additions and 9 deletions

View File

@@ -254,11 +254,13 @@ export class Extension<Options = any> {
}
configure(options: Partial<Options> = {}) {
this.options = mergeDeep(this.options, options) as Options
// return a new instance so we can use the same extension
// with different calls of `configure`
return this.extend()
const extension = this.extend()
extension.options = mergeDeep(this.options, options) as Options
return extension
}
extend<ExtendedOptions = Options>(extendedConfig: Partial<ExtensionConfig<ExtendedOptions>> = {}) {

View File

@@ -351,11 +351,13 @@ export class Mark<Options = any> {
}
configure(options: Partial<Options> = {}) {
this.options = mergeDeep(this.options, options) as Options
// return a new instance so we can use the same extension
// with different calls of `configure`
return this.extend()
const extension = this.extend()
extension.options = mergeDeep(this.options, options) as Options
return extension
}
extend<ExtendedOptions = Options>(extendedConfig: Partial<MarkConfig<ExtendedOptions>> = {}) {

View File

@@ -432,11 +432,13 @@ export class Node<Options = any> {
}
configure(options: Partial<Options> = {}) {
this.options = mergeDeep(this.options, options) as Options
// return a new instance so we can use the same extension
// with different calls of `configure`
return this.extend()
const extension = this.extend()
extension.options = mergeDeep(this.options, options) as Options
return extension
}
extend<ExtendedOptions = Options>(extendedConfig: Partial<NodeConfig<ExtendedOptions>> = {}) {

View File

@@ -127,11 +127,13 @@ describe('extension options', () => {
.create({
defaultOptions: {
foo: 1,
bar: 2,
},
})
const extension1 = extension.configure({
foo: 2,
bar: 4,
})
const extension2 = extension.configure({
@@ -140,10 +142,12 @@ describe('extension options', () => {
expect(extension1.options).to.deep.eq({
foo: 2,
bar: 4,
})
expect(extension2.options).to.deep.eq({
foo: 3,
bar: 2,
})
})
})