clean file import syntax bindings

This commit is contained in:
jean-emmanuel 2022-01-10 11:26:06 +01:00
parent 9addc60df6
commit 708a62613d

View file

@ -198,6 +198,7 @@ class Widget extends EventEmitter {
this.parsers = {}
this.parsersLocalScope = options.locals || {}
this.variables = options.variables || {}
this.fragments = {}
this.createPropsCache()
@ -391,6 +392,9 @@ class Widget extends EventEmitter {
}
this.oscReceivers = {}
// IMPORT{} fragments
this.fragments = {}
// Cache resolved props
this.cachedProps = {}
this.cachedProps.uuid = this.hash
@ -446,6 +450,22 @@ class Widget extends EventEmitter {
}
if (!this.linkedFragmentCallback && Object.keys(this.fragments).length) {
this.linkedFragmentCallback = (e)=>{
var {path} = e
if (this.fragments[path]) this.updateProps(this.fragments[path])
}
sessionManager.on('fragment-updated', this.linkedFragmentCallback, {context: this})
} else if (this.linkedFragmentCallback && !Object.keys(this.fragments).length) {
sessionManager.off('fragment-updated', this.linkedFragmentCallback)
delete this.linkedFragmentCallback
}
var selfLinkedOSCProps = (this.linkedPropsValue['this'] || []).filter(i=>OSCProps.indexOf(i) > -1)
this.selfLinkedOSCProps = selfLinkedOSCProps.length ? selfLinkedOSCProps : false
@ -696,19 +716,15 @@ class Widget extends EventEmitter {
return varname
})
propValue = balancedReplace('IMPORT', '{', '}', propValue, (args)=>{
propValue = balancedReplace('IMPORT', '{', '}', propValue, (file)=>{
if (storeLinks) {
sessionManager.on('fragment-updated', (e)=>{
var {path} = e
if (path === args) {
this.updateProps([propName])
}
}, {context: this})
if (!this.fragments[file]) this.fragments[file] = []
if (!this.fragments[file].includes(propName)) this.fragments[file].push(propName)
}
if (sessionManager.getFragment(args)) {
return sessionManager.getFragment(args)
if (sessionManager.getFragment(file)) {
return sessionManager.getFragment(file)
} else {
sessionManager.loadFragment(args)
sessionManager.loadFragment(file)
return ''
}
})