--- a/svghmi/svghmi.js Wed Aug 05 18:49:29 2020 +0200
+++ b/svghmi/svghmi.js Wed Aug 05 18:53:56 2020 +0200
@@ -4,25 +4,6 @@
var need_cache_apply = [];
-function dispatch_value_to_widget(widget, index, value, oldval) {
- let idx = widget.offset ? index - widget.offset : index;
- let idxidx = widget.indexes.indexOf(idx);
- let d = widget.dispatch;
- if(typeof(d) == "function" && idxidx == 0){
- d.call(widget, value, oldval);
- else if(typeof(d) == "object" && d.length >= idxidx){
- d[idxidx].call(widget, value, oldval);
- /* else dispatch_0, ..., dispatch_n ? */
- throw new Error("Dunno how to dispatch to widget at index = " + index);
function dispatch_value(index, value) {
let widgets = subscribers[index];
@@ -32,7 +13,7 @@
for(let widget of widgets){
- dispatch_value_to_widget(widget, index, value, oldval);
+ widget.new_hmi_value(index, value, oldval); @@ -190,7 +171,7 @@
indexes: [heartbeat_index],
- dispatch: function(value) {
+ new_hmi_value: function(index, value, oldval) { apply_hmi_value(heartbeat_index, value+1);
--- a/svghmi/widgets_common.ysl2 Wed Aug 05 18:49:29 2020 +0200
+++ b/svghmi/widgets_common.ysl2 Wed Aug 05 18:53:56 2020 +0200
@@ -109,7 +109,7 @@
let realindex = index+this.offset;
let cached_val = cache[realindex];
if(cached_val != undefined)
- dispatch_value_to_widget(this, realindex, cached_val, cached_val);
+ this.new_hmi_value(realindex, cached_val, cached_val); @@ -124,6 +124,34 @@
apply_hmi_value(index, new_val) {
return apply_hmi_value(this.get_idx(0), new_val);
+ new_hmi_value(index, value, oldval) { + // TODO avoid searching, store index at sub() + for(let i = 0; i < this.indexes.length; i++) { + let refindex = this.indexes[i]; + if(this.relativeness[i]) + refindex += this.offset; + if(index == refindex) { + if(typeof(d) == "function"){ + d.call(this, value, oldval, i); + else if(typeof(d) == "object"){ + d[i].call(this, value, oldval); + /* else dispatch_0, ..., dispatch_n ? */ + throw new Error("Dunno how to dispatch to widget at index = " + index);