Skip to content

Commit

Permalink
[MainUI] Blockly: Add compatibility code for JS Scripting
Browse files Browse the repository at this point in the history
Based on openhab#1170.

Also-by: Yannick Schaus <github@schaus.net>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
  • Loading branch information
florian-h05 committed Jan 8, 2023
1 parent 102406f commit ed16a6f
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,14 @@ Vue.config.ignoredElements = [
'sep'
]
// Code to prepend when running on GraalJS. When all Blocks are migrated to native GraalJS code, this can be removed.
const prependCode = `var ctx = this;
var runtime = require('@runtime');
var itemRegistry = runtime.itemRegistry;
var events = runtime.events;
`
export default {
props: ['blocks', 'libraryDefinitions'],
data () {
Expand Down Expand Up @@ -1061,7 +1069,7 @@ export default {
return Blockly.Xml.domToText(xml)
},
getCode () {
return Blockly.JavaScript.workspaceToCode(this.workspace)
return (this.jsScriptingAvailable === true ? prependCode : '') + Blockly.JavaScript.workspaceToCode(this.workspace)
},
getType () {
return this.jsScriptingAvailable === true ? 'application/javascript;version=ECMAScript-2021' : 'application/javascript'
Expand Down

0 comments on commit ed16a6f

Please sign in to comment.