make options for extensions reactive

changing options will call the update method off the extension.
This commit is contained in:
Chrissi2812 2019-02-25 16:20:02 +01:00
parent 3de6b13004
commit 45945e2c09
No known key found for this signature in database
GPG Key ID: B4B82C7E618271DA
3 changed files with 30 additions and 0 deletions

View File

@ -67,6 +67,10 @@ export default class Editor {
view: this.view,
state: this.state,
})
// give extension manager access to our view and state
this.extensions.state = this.state
this.extensions.view = this.view
}
setOptions(options) {

View File

@ -15,6 +15,10 @@ export default class Extension {
return 'extension'
}
get update() {
return () => {}
}
get defaultOptions() {
return {}
}

View File

@ -15,6 +15,28 @@ export default class ExtensionManager {
}), {})
}
get options() {
const { state, view } = this
return this.extensions
// { name, options, update = () => {} }
.reduce((nodes, extension) => ({
...nodes,
[extension.name]: new Proxy(extension.options, {
set(obj, prop, value) {
const changed = (obj[prop] !== value)
obj[prop] = value
if (changed) {
extension.update({ state, view })
}
return true
},
}),
}), {})
}
get marks() {
return this.extensions
.filter(extension => extension.type === 'mark')