--- a/svghmi/gen_index_xhtml.xslt Thu Mar 05 13:54:29 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt Fri Mar 06 09:35:08 2020 +0100
@@ -623,6 +623,8 @@
<xsl:text>var cache = hmitree_types.map(_ignored => undefined);
+ <xsl:text>var updates = {}; <xsl:text>function dispatch_value_to_widget(widget, index, value, oldval) {
@@ -749,7 +751,33 @@
- <xsl:text>// Register message reception handler
+ <xsl:text>// Apply updates recieved through ws.onmessage to subscribed widgets + <xsl:text>// Called on requestAnimationFram, modifies DOM + <xsl:text>function apply_pending_updates() { + <xsl:text> for(let index in updates){ + <xsl:text> // serving as a key, index becomes a string + <xsl:text> // -> pass Number(index) instead + <xsl:text> dispatch_value(Number(index), updates[index]); + <xsl:text> delete updates[index]; + <xsl:text>// Message reception handler + <xsl:text>// Hash is verified and HMI values updates resulting from binary parsing + <xsl:text>// are stored until browser can compute next frame, DOM is left untouched <xsl:text>ws.onmessage = function (evt) {
@@ -791,18 +819,22 @@
<xsl:text> let [value, bytesize] = dvgetter(dv,i);
- <xsl:text> dispatch_value(index, value);
+ <xsl:text> updates[index] = value; <xsl:text> i += bytesize;
- <xsl:text> throw new Error("Unknown index "+index)
+ <xsl:text> throw new Error("Unknown index "+index); + <xsl:text> // register for rendering on next frame, since there are updates + <xsl:text> window.requestAnimationFrame(apply_pending_updates); <xsl:text> } catch(err) {
<xsl:text> // 1003 is for "Unsupported Data"
--- a/svghmi/svghmi.js Thu Mar 05 13:54:29 2020 +0100
+++ b/svghmi/svghmi.js Fri Mar 06 09:35:08 2020 +0100
@@ -1,6 +1,7 @@
var cache = hmitree_types.map(_ignored => undefined);
function dispatch_value_to_widget(widget, index, value, oldval) {
@@ -64,7 +65,20 @@
-// Register message reception handler
+// Apply updates recieved through ws.onmessage to subscribed widgets +// Called on requestAnimationFrame, modifies DOM +function apply_pending_updates() { + for(let index in updates){ + // serving as a key, index becomes a string + // -> pass Number(index) instead + dispatch_value(Number(index), updates[index]); +// Message reception handler +// Hash is verified and HMI values updates resulting from binary parsing +// are stored until browser can compute next frame, DOM is left untouched ws.onmessage = function (evt) {
@@ -85,12 +99,14 @@
if(iectype != undefined){
let dvgetter = dvgetters[iectype];
let [value, bytesize] = dvgetter(dv,i);
- dispatch_value(index, value);
+ updates[index] = value; - throw new Error("Unknown index "+index)
+ throw new Error("Unknown index "+index); + // register for rendering on next frame, since there are updates + window.requestAnimationFrame(apply_pending_updates); // 1003 is for "Unsupported Data"
// ws.close(1003, err.message);