SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes. svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Fri, 08 May 2020 16:47:52 +0200
branchsvghmi
changeset 2948 faaf677ea99d
parent 2947 25f593573579
child 2949 e50908ddec60
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
svghmi/widgets_common.ysl2
--- a/svghmi/widgets_common.ysl2	Fri May 08 16:44:20 2020 +0200
+++ b/svghmi/widgets_common.ysl2	Fri May 08 16:47:52 2020 +0200
@@ -47,6 +47,31 @@
     apply "$widget", mode="widget_defs" with "hmi_element",".";
     apply "$widget", mode="widget_subscribe" with "hmi_element",".";
     |   }`if "position()!=last()" > ,`
+
+def "func:unique_types" {
+    param "elts_with_type";
+    choose {
+        when "count($elts_with_type) > 1" {
+            const "prior_results","func:unique_types($elts_with_type[position()!=last()])";
+            choose {
+                when "$elts_with_type[last()][@type = $prior_results/@type]"{
+                    // type already in
+                    result "$prior_results";
+                }
+                otherwise {
+                    result "$prior_results | $elts_with_type[last()]";
+                }
+            }
+        }
+        otherwise {
+            result "$elts_with_type";
+        }
+    }
+}
+
+emit "preamble:hmi-classes" {
+    const "used_widget_types", "func:unique_types($parsed_widgets/widget)";
+    apply "$used_widget_types", mode="widget_class";
 }
 
 emit "preamble:hmi-elements" {