Added support in the Node web server for scripts on web pages, too

This commit is contained in:
Jeff Parsons 2017-01-25 11:45:22 -08:00 committed by Jeff Parsons
commit 25af103509
10 changed files with 88 additions and 45 deletions

View file

@ -105,7 +105,18 @@ class Component {
this.name = parms['name'];
this.comment = parms['comment'];
this.parms = parms;
this['exports'] = {};
/*
* The following Component properties need to be accessible by other machines and/or command scripts;
* well, OK, or we could have exported some new functions to walk the contents of these properties, as we
* did with findMachineComponent(), but this works just as well.
*
* Also, while the double-assignment looks silly (ie, using both dot and bracket property notation), it
* resolves a complaint from the Closure Compiler, because if we use ONLY bracket notation here, then the
* Compiler wants us to change all the other references to bracket notation as well.
*/
this.exports = this['exports'] = {};
this.bindings = this['bindings'] = {};
var i = this.id.indexOf('.');
if (i < 0) {
@ -129,7 +140,6 @@ class Component {
this.fnReady = null;
this.clearError();
this.bindings = {};
this.bitsMessage = bitsMessage || 0;
/** @type {Object|null} controlPrint is the HTML control, if any, that we can print to */

View file

@ -112,15 +112,19 @@ function commandMachine(idMachine, sComponent, sCommand, sValue)
if (window.findMachineComponent) {
var component = window.findMachineComponent(idMachine, sComponent);
if (component) {
var exports = component['exports'];
if (exports) {
var fnCommand = exports[sCommand];
if (fnCommand) {
//noinspection JSUnresolvedFunction
if (!fnCommand.call(component, sValue)) {
window.alert("Error calling " + idMachine + "." + sComponent + "." + sCommand + "(" + sValue + ")");
if (sCommand == "script") {
window.alert("commandScript('" + sValue + "')");
} else {
var exports = component['exports'];
if (exports) {
var fnCommand = exports[sCommand];
if (fnCommand) {
//noinspection JSUnresolvedFunction
if (!fnCommand.call(component, sValue)) {
window.alert("Error calling " + idMachine + "." + sComponent + "." + sCommand + "(" + sValue + ")");
}
return;
}
return;
}
}
}