2 |
2 |
3 var cache = hmitree_types.map(_ignored => undefined); |
3 var cache = hmitree_types.map(_ignored => undefined); |
4 |
4 |
5 function dispatch_value(index, value) { |
5 function dispatch_value(index, value) { |
6 let widgets = subscribers[index]; |
6 let widgets = subscribers[index]; |
|
7 |
|
8 let oldval = cache[index]; |
|
9 cache[index] = value; |
7 |
10 |
8 if(widgets.size > 0) { |
11 if(widgets.size > 0) { |
9 for(let widget of widgets){ |
12 for(let widget of widgets){ |
10 let idxidx = widget.indexes.indexOf(index); |
13 let idxidx = widget.indexes.indexOf(index); |
11 if(idxidx == -1){ |
14 if(idxidx == -1){ |
12 throw new Error("Dispatching to widget not interested, should not happen."); |
15 throw new Error("Dispatching to widget not interested, should not happen."); |
13 } |
16 } |
14 let d = widget.dispatch; |
17 let d = widget.dispatch; |
15 if(typeof(d) == "function" && idxidx == 0){ |
18 if(typeof(d) == "function" && idxidx == 0){ |
16 return d.call(widget,value); |
19 return d.call(widget, value, oldval); |
17 }else if(typeof(d) == "object" && d.length >= idxidx){ |
20 }else if(typeof(d) == "object" && d.length >= idxidx){ |
18 d[idxidx].call(widget,value); |
21 return d[idxidx].call(widget, value, oldval); |
19 }/* else dispatch_0, ..., dispatch_n ? */ |
22 }/* else dispatch_0, ..., dispatch_n ? */ |
20 /*else { |
23 /*else { |
21 throw new Error("Dunno how to dispatch to widget at index = " + index); |
24 throw new Error("Dunno how to dispatch to widget at index = " + index); |
22 }*/ |
25 }*/ |
23 } |
26 } |
24 } |
27 } |
25 |
|
26 cache[index] = value; |
|
27 |
|
28 }; |
28 }; |
29 |
29 |
30 function init_widgets() { |
30 function init_widgets() { |
31 Object.keys(hmi_widgets).forEach(function(id) { |
31 Object.keys(hmi_widgets).forEach(function(id) { |
32 let widget = hmi_widgets[id]; |
32 let widget = hmi_widgets[id]; |