Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Blockly OH blocks compatible with the JSScripting add-on #1170

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -440,6 +440,17 @@ import defineOHBlocks from '@/assets/definitions/blockly/ohblocks'

Vue.config.ignoredElements = ['field', 'block', 'category', 'xml', 'mutation', 'value', 'sep']

// Code to prepend to have a common API to openHAB objects when running GraalVM JS or Nashorn.
const prependCode = `
if (typeof(require) === "function") {
ctx = this;
var runtime = require("@runtime");
itemRegistry = runtime.itemRegistry;
events = runtime.events;
}

`

export default {
props: ['blocks'],
data () {
Expand Down Expand Up @@ -470,7 +481,7 @@ export default {
return Blockly.Xml.domToText(xml)
},
getCode () {
return Blockly.JavaScript.workspaceToCode(this.workspace)
return prependCode + Blockly.JavaScript.workspaceToCode(this.workspace)
},
onChange (event) {
if (event.type === Blockly.Events.FINISHED_LOADING) {
Expand Down