SVGHMI: cosmetic code moving svghmi
authorEdouard Tisserant
Thu, 12 Mar 2020 09:33:20 +0100
branchsvghmi
changeset 2865 545902730141
parent 2864 36f78f6cfabd
child 2866 59a855c17aa6
SVGHMI: cosmetic code moving
svghmi/gen_index_xhtml.xslt
svghmi/svghmi.js
--- a/svghmi/gen_index_xhtml.xslt	Tue Mar 10 13:57:29 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt	Thu Mar 12 09:33:20 2020 +0100
@@ -753,31 +753,41 @@
 </xsl:text>
     <xsl:text>// Apply updates recieved through ws.onmessage to subscribed widgets
 </xsl:text>
-    <xsl:text>// Do the page swith if any one pending
+    <xsl:text>function apply_updates() {
+</xsl:text>
+    <xsl:text>    for(let index in updates){
+</xsl:text>
+    <xsl:text>        // serving as a key, index becomes a string
+</xsl:text>
+    <xsl:text>        // -&gt; pass Number(index) instead
+</xsl:text>
+    <xsl:text>        dispatch_value(Number(index), updates[index]);
+</xsl:text>
+    <xsl:text>        delete updates[index];
+</xsl:text>
+    <xsl:text>    }
+</xsl:text>
+    <xsl:text>}
+</xsl:text>
+    <xsl:text>
 </xsl:text>
     <xsl:text>// Called on requestAnimationFrame, modifies DOM
 </xsl:text>
+    <xsl:text>var requestAnimationFrameID = null;
+</xsl:text>
     <xsl:text>function animate() {
 </xsl:text>
+    <xsl:text>    // Do the page swith if any one pending
+</xsl:text>
     <xsl:text>    if(current_subscribed_page != current_visible_page){
 </xsl:text>
     <xsl:text>        switch_visible_page(current_subscribed_page);
 </xsl:text>
     <xsl:text>    }
 </xsl:text>
-    <xsl:text>
-</xsl:text>
-    <xsl:text>    for(let index in updates){
-</xsl:text>
-    <xsl:text>        // serving as a key, index becomes a string
-</xsl:text>
-    <xsl:text>        // -&gt; pass Number(index) instead
-</xsl:text>
-    <xsl:text>        dispatch_value(Number(index), updates[index]);
-</xsl:text>
-    <xsl:text>        delete updates[index];
-</xsl:text>
-    <xsl:text>    }
+    <xsl:text>    console.log("no page switch");
+</xsl:text>
+    <xsl:text>    apply_updates();
 </xsl:text>
     <xsl:text>    requestAnimationFrameID = null;
 </xsl:text>
@@ -785,8 +795,6 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
-    <xsl:text>var requestAnimationFrameID = null;
-</xsl:text>
     <xsl:text>function requestHMIAnimation() {
 </xsl:text>
     <xsl:text>    if(requestAnimationFrameID == null){
--- a/svghmi/svghmi.js	Tue Mar 10 13:57:29 2020 +0100
+++ b/svghmi/svghmi.js	Thu Mar 12 09:33:20 2020 +0100
@@ -66,23 +66,27 @@
 };
 
 // Apply updates recieved through ws.onmessage to subscribed widgets
-// Do the page swith if any one pending
-// Called on requestAnimationFrame, modifies DOM
-function animate() {
-    if(current_subscribed_page != current_visible_page){
-        switch_visible_page(current_subscribed_page);
-    }
-
+function apply_updates() {
     for(let index in updates){
         // serving as a key, index becomes a string
         // -> pass Number(index) instead
         dispatch_value(Number(index), updates[index]);
         delete updates[index];
     }
+}
+
+// Called on requestAnimationFrame, modifies DOM
+var requestAnimationFrameID = null;
+function animate() {
+    // Do the page swith if any one pending
+    if(current_subscribed_page != current_visible_page){
+        switch_visible_page(current_subscribed_page);
+    }
+    console.log("no page switch");
+    apply_updates();
     requestAnimationFrameID = null;
 }
 
-var requestAnimationFrameID = null;
 function requestHMIAnimation() {
     if(requestAnimationFrameID == null){
         requestAnimationFrameID = window.requestAnimationFrame(animate);