SVGHMI: remove intermediate "updates" Map and apply_updates()
authorEdouard Tisserant
Thu, 22 Sep 2022 09:42:38 +0200
changeset 3624 770c613c424f
parent 3623 0237c28cd172
child 3625 bb1eff4091ab
SVGHMI: remove intermediate "updates" Map and apply_updates()

It was used initially to decouple DOM updates from reception of data through
websocket, but now since all widget SHOULD use animate() to modify DOM, and
dispatch() only change internal state, apply_update is unnecessary.
svghmi/svghmi.js
svghmi/widgets_common.ysl2
--- a/svghmi/svghmi.js	Wed Sep 21 11:51:05 2022 +0200
+++ b/svghmi/svghmi.js	Thu Sep 22 09:42:38 2022 +0200
@@ -46,14 +46,6 @@
     }
 };
 
-// Apply updates recieved through ws.onmessage to subscribed widgets
-function apply_updates() {
-    updates.forEach((value, index) => {
-        dispatch_value(index, value);
-    });
-    updates.clear();
-}
-
 // Called on requestAnimationFrame, modifies DOM
 var requestAnimationFrameID = null;
 function animate() {
@@ -126,14 +118,13 @@
             if(iectype != undefined){
                 let dvgetter = dvgetters[iectype];
                 let [value, bytesize] = dvgetter(dv,i);
-                updates.set(index, value);
+                dispatch_value(index, value);
                 i += bytesize;
             } else {
                 throw new Error("Unknown index "+index);
             }
         };
 
-        apply_updates();
         // register for rendering on next frame, since there are updates
     } catch(err) {
         // 1003 is for "Unsupported Data"
--- a/svghmi/widgets_common.ysl2	Wed Sep 21 11:51:05 2022 +0200
+++ b/svghmi/widgets_common.ysl2	Thu Sep 22 09:42:38 2022 +0200
@@ -189,7 +189,6 @@
     ]);
     var persistent_indexes = new Map();
     var cache = hmitree_types.map(_ignored => undefined);
-    var updates = new Map();
 
     function page_local_index(varname, pagename){
         let pagevars = hmi_locals[pagename];
@@ -209,7 +208,6 @@
         let defaultval = local_defaults[varname];
         if(defaultval != undefined) {
             cache[new_index] = defaultval; 
-            updates.set(new_index, defaultval);
             if(persistent_locals.has(varname))
                 persistent_indexes.set(new_index, varname);
         }