refactoring

This commit is contained in:
Philipp Kühn
2020-09-09 21:06:57 +02:00
parent b4bb05794a
commit dca42879e4
2 changed files with 53 additions and 60 deletions

View File

@@ -0,0 +1,35 @@
import deepmerge from 'deepmerge'
import Extension from '../Extension'
import Node from '../Node'
import Mark from '../Mark'
export default function resolveExtensionConfig(
extension: Extension | Node | Mark,
name: string,
props = {},
): void {
if (!extension.configs[name]) {
return
}
extension.config[name] = extension.configs[name]
.reduce((accumulator, { stategy, value: rawValue }) => {
const value = typeof rawValue === 'function'
? rawValue(props)
: rawValue
if (accumulator === undefined) {
return value
}
if (stategy === 'overwrite') {
return value
}
if (stategy === 'extend') {
return deepmerge(accumulator, value)
}
return accumulator
}, undefined)
}