svghmi/svghmi.js
branchsvghmi
changeset 2834 6ac6a9dff594
parent 2829 4c2c50f60730
child 2836 ce6cecdb7320
equal deleted inserted replaced
2833:e74123b966ac 2834:6ac6a9dff594
     1 // svghmi.js
     1 // svghmi.js
     2 
     2 
     3 var cache = hmitree_types.map(_ignored => undefined);
     3 var cache = hmitree_types.map(_ignored => undefined);
     4 
     4 
     5 function dispatch_value_to_widget(widget, index, value, oldval) {
     5 function dispatch_value_to_widget(widget, index, value, oldval) {
     6     let idxidx = widget.indexes.indexOf(index);
     6     try {
     7     if(idxidx == -1){
     7         let idxidx = widget.indexes.indexOf(index);
     8         throw new Error("Dispatching to widget not interested, should not happen.");
     8         let d = widget.dispatch;
     9     }
     9         if(typeof(d) == "function" && idxidx == 0){
    10     let d = widget.dispatch;
    10             d.call(widget, value, oldval);
    11     if(typeof(d) == "function" && idxidx == 0){
    11         }else if(typeof(d) == "object" && d.length >= idxidx){
    12         return d.call(widget, value, oldval);
    12             d[idxidx].call(widget, value, oldval);
    13     }else if(typeof(d) == "object" && d.length >= idxidx){
    13         }/* else dispatch_0, ..., dispatch_n ? */
    14         return d[idxidx].call(widget, value, oldval);
    14         /*else {
    15     }/* else dispatch_0, ..., dispatch_n ? */
    15             throw new Error("Dunno how to dispatch to widget at index = " + index);
    16     /*else {
    16         }*/
    17         throw new Error("Dunno how to dispatch to widget at index = " + index);
    17     }
    18     }*/
       
    19 }
    18 }
    20 
    19 
    21 function dispatch_value(index, value) {
    20 function dispatch_value(index, value) {
    22     let widgets = subscribers[index];
    21     let widgets = subscribers[index];
    23 
    22 
    34 function init_widgets() {
    33 function init_widgets() {
    35     Object.keys(hmi_widgets).forEach(function(id) {
    34     Object.keys(hmi_widgets).forEach(function(id) {
    36         let widget = hmi_widgets[id];
    35         let widget = hmi_widgets[id];
    37         let init = widget.init;
    36         let init = widget.init;
    38         if(typeof(init) == "function"){
    37         if(typeof(init) == "function"){
    39             return init.call(widget);
    38             try {
       
    39                 init.call(widget);
       
    40             } catch(err) {
       
    41                 console.log("Widget initialization error : "+err.message);
       
    42 
       
    43             }
    40         }
    44         }
    41     });
    45     });
    42 };
    46 };
    43 
    47 
    44 // Open WebSocket to relative "/ws" address
    48 // Open WebSocket to relative "/ws" address