Merge pull request #298 from jjangga0214/refactor/ExtensionManager.js

refactor src/Utils/ExtensionManager.js
This commit is contained in:
Philipp Kühn
2019-05-08 09:46:48 +02:00
committed by GitHub

View File

@@ -137,44 +137,28 @@ export default class ExtensionManager {
} : {},
})
if (Array.isArray(value)) {
commands[name] = attrs => value
.forEach(callback => {
const apply = (cb, attrs) => {
if (!editable) {
return false
}
view.focus()
return callback(attrs)(view.state, view.dispatch, view)
})
} else if (typeof value === 'function') {
commands[name] = attrs => {
if (!editable) {
return false
return cb(attrs)(view.state, view.dispatch, view)
}
view.focus()
return value(attrs)(view.state, view.dispatch, view)
const handle = (_name, _value) => {
if (Array.isArray(_value)) {
commands[_name] = attrs => _value.forEach(callback => apply(callback, attrs))
} else if (typeof _value === 'function') {
commands[_name] = attrs => apply(_value, attrs)
}
} else if (typeof value === 'object') {
}
if (typeof value === 'object') {
Object.entries(value).forEach(([commandName, commandValue]) => {
if (Array.isArray(commandValue)) {
commands[commandName] = attrs => commandValue
.forEach(callback => {
if (!editable) {
return false
}
view.focus()
return callback(attrs)(view.state, view.dispatch, view)
handle(commandName, commandValue)
})
} else {
commands[commandName] = attrs => {
if (!editable) {
return false
}
view.focus()
return commandValue(attrs)(view.state, view.dispatch, view)
}
}
})
handle(name, value)
}
return {