editor: move linked props check to widget base class to ensure clone and matrix apply it

This commit is contained in:
jean-emmanuel 2019-01-01 22:04:42 +01:00
parent 28ab560f80
commit b6fa6baa57
4 changed files with 31 additions and 22 deletions

View file

@ -16,30 +16,14 @@ function updateWidget(widget, options={}) {
if (options.changedProps) {
// alternate routine for small edits
var propNames = options.changedProps,
propValues = propNames.map(x => widget.props[x]),
linkedProps = []
Object.values(widget.nestedLinkedProps).forEach(l => linkedProps = linkedProps.concat(l))
Object.values(widget.linkedProps).forEach(l => linkedProps = linkedProps.concat(l))
Object.values(widget.linkedPropsValue).forEach(l => linkedProps = linkedProps.concat(l))
Object.values(widget.oscReceivers).forEach(r => linkedProps = linkedProps.concat(r.propNames))
var propNames = options.changedProps
if (
// if non dynamic props have changed, skip this and use rebuild routine
!propNames.some(n => !widget.isDynamicProp(n))
) {
var edited = widget.updateProps(options.changedProps, null) || widget
if (
// if prop/osc listeners have changed (@{} / OSC{})
// refresh the widget's props cache and update linked props bindings
propValues.some(x => typeof x === 'string' && x.match(/OSC\{|@\{/))
|| propNames.some(n => linkedProps.includes(n))
) {
widget.createPropsCache()
}
var edited = widget.updateProps(options.changedProps, null, {fromEditor: true}) || widget
if (editor.selectedWidgets.includes(widget) && !options.preventSelect) {
editor.select(edited)

View file

@ -268,6 +268,27 @@ class Widget extends EventEmitter {
getSplit() {}
checkLinkedProps(propNames) {
// Dynamic props cache check
var linkedProps = []
Object.values(this.nestedLinkedProps).forEach(l => linkedProps = linkedProps.concat(l))
Object.values(this.linkedProps).forEach(l => linkedProps = linkedProps.concat(l))
Object.values(this.linkedPropsValue).forEach(l => linkedProps = linkedProps.concat(l))
Object.values(this.oscReceivers).forEach(r => linkedProps = linkedProps.concat(r.propNames))
if (
// if prop/osc listeners have changed (@{} / OSC{})
// refresh the widget's props cache and update linked props bindings
propNames.map(x => this.props[x]).some(x => typeof x === 'string' && x.match(/OSC\{|@\{/))
|| propNames.some(n => linkedProps.includes(n))
) {
this.createPropsCache()
}
}
createPropsCache() {
// @{props} links lists
@ -656,6 +677,10 @@ class Widget extends EventEmitter {
} else if (changedProps.length) {
if (options && options.fromEditor) {
this.checkLinkedProps(propNames)
}
for (var i in changedProps) {
this.onPropChanged(changedProps[i].propName, options, changedProps[i].oldPropValue)

View file

@ -78,7 +78,7 @@ class Clone extends Container {
if (e.widget === this.cloneTarget || this.cloneTarget.contains(e.widget)) {
this.updateClone()
this.updateClone(e.options)
}
@ -189,7 +189,7 @@ class Clone extends Container {
}
updateClone() {
updateClone(options) {
if (this.cloneLock) return
@ -214,7 +214,7 @@ class Clone extends Container {
} else {
widget.updateProps(changedProps, this)
widget.updateProps(changedProps, this, options)
this.updateContainer(true)
}

View file

@ -90,7 +90,7 @@ class Matrix extends _matrix_base {
if (typeof data === 'object' && data !== null) {
Object.assign(this.children[i].props, data)
}
this.children[i].updateProps(Object.keys(data), this)
this.children[i].updateProps(Object.keys(data), this, options)
// this.children[i] might have been recreated
this.children[i].container.classList.add('not-editable')