fix: fix a bug when configurating the same extension multiple times
This commit is contained in:
@@ -256,7 +256,9 @@ export class Extension<Options = any> {
|
|||||||
configure(options: Partial<Options> = {}) {
|
configure(options: Partial<Options> = {}) {
|
||||||
this.options = mergeDeep(this.options, options) as Options
|
this.options = mergeDeep(this.options, options) as Options
|
||||||
|
|
||||||
return this
|
// return a new instance so we can use the same extension
|
||||||
|
// with different calls of `configure`
|
||||||
|
return this.extend()
|
||||||
}
|
}
|
||||||
|
|
||||||
extend<ExtendedOptions = Options>(extendedConfig: Partial<ExtensionConfig<ExtendedOptions>> = {}) {
|
extend<ExtendedOptions = Options>(extendedConfig: Partial<ExtensionConfig<ExtendedOptions>> = {}) {
|
||||||
|
|||||||
@@ -353,7 +353,9 @@ export class Mark<Options = any> {
|
|||||||
configure(options: Partial<Options> = {}) {
|
configure(options: Partial<Options> = {}) {
|
||||||
this.options = mergeDeep(this.options, options) as Options
|
this.options = mergeDeep(this.options, options) as Options
|
||||||
|
|
||||||
return this
|
// return a new instance so we can use the same extension
|
||||||
|
// with different calls of `configure`
|
||||||
|
return this.extend()
|
||||||
}
|
}
|
||||||
|
|
||||||
extend<ExtendedOptions = Options>(extendedConfig: Partial<MarkConfig<ExtendedOptions>> = {}) {
|
extend<ExtendedOptions = Options>(extendedConfig: Partial<MarkConfig<ExtendedOptions>> = {}) {
|
||||||
|
|||||||
@@ -434,7 +434,9 @@ export class Node<Options = any> {
|
|||||||
configure(options: Partial<Options> = {}) {
|
configure(options: Partial<Options> = {}) {
|
||||||
this.options = mergeDeep(this.options, options) as Options
|
this.options = mergeDeep(this.options, options) as Options
|
||||||
|
|
||||||
return this
|
// return a new instance so we can use the same extension
|
||||||
|
// with different calls of `configure`
|
||||||
|
return this.extend()
|
||||||
}
|
}
|
||||||
|
|
||||||
extend<ExtendedOptions = Options>(extendedConfig: Partial<NodeConfig<ExtendedOptions>> = {}) {
|
extend<ExtendedOptions = Options>(extendedConfig: Partial<NodeConfig<ExtendedOptions>> = {}) {
|
||||||
|
|||||||
@@ -121,4 +121,29 @@ describe('extension options', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should create its own instance on configure', () => {
|
||||||
|
const extension = Extension
|
||||||
|
.create({
|
||||||
|
defaultOptions: {
|
||||||
|
foo: 1,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const extension1 = extension.configure({
|
||||||
|
foo: 2,
|
||||||
|
})
|
||||||
|
|
||||||
|
const extension2 = extension.configure({
|
||||||
|
foo: 3,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(extension1.options).to.deep.eq({
|
||||||
|
foo: 2,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(extension2.options).to.deep.eq({
|
||||||
|
foo: 3,
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user