scripting: onCreate: expose value and call onCreate after default value is applied

This commit is contained in:
jean-emmanuel 2022-11-29 08:57:38 +01:00
parent 6ef1d412f9
commit 5230eb2d4b
6 changed files with 14 additions and 4 deletions

View file

@ -87,8 +87,6 @@ var Parser = class Parser {
widgetManager.addWidget(widget)
widget.created(index)
// set widget's initial state
var defaultValue = widget.getProp('default'),
currentValue = widget.getProp('value')
@ -103,6 +101,8 @@ var Parser = class Parser {
}
widget.created(index)
parentNode.appendChild(widget.container)
widget.mounted = true

View file

@ -167,6 +167,8 @@ class CodeEditor {
let globals = {}
if (this.name === 'onKeyboard') {
globals = {type: true, key: true, code: true, ctrl: true, shift: true, alt: true, meta: true}
} else if (this.name === 'onCreate') {
globals = {value: true}
} else if (this.name === 'onValue') {
globals = {id: true, value: true, touch: true}
} else if (this.name === 'onDraw') {

View file

@ -232,7 +232,7 @@ class Widget extends EventEmitter {
widget: this,
property: 'onCreate',
code: this.getProp('onCreate'),
context: {}
context: {value: 0}
})
}
@ -337,7 +337,7 @@ class Widget extends EventEmitter {
index: index
})
if (this.scripts.onCreate) this.scripts.onCreate.run({}, {sync: true, send: true, onCreate: true})
if (this.scripts.onCreate) this.scripts.onCreate.run({value: this.value}, {sync: true, send: true, onCreate: true})
}