SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class. svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Sun, 10 May 2020 16:34:44 +0200
branchsvghmi
changeset 2951 506fe9272660
parent 2950 1e53d8b60ee9
child 2952 2adfce8908b4
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
svghmi/svghmi.js
svghmi/widgets_common.ysl2
--- a/svghmi/svghmi.js	Sun May 10 16:32:19 2020 +0200
+++ b/svghmi/svghmi.js	Sun May 10 16:34:44 2020 +0200
@@ -325,40 +325,6 @@
     return true;
 };
 
-function* chain(a,b){
-    yield* a;
-    yield* b;
-};
-
-function unsubscribe(){
-    /* remove subsribers */
-    for(let index of this.indexes){
-        let idx = index + this.offset;
-        subscribers[idx].delete(this);
-    }
-    this.offset = 0;
-}
-
-function subscribe(new_offset=0){
-    /* set the offset because relative */
-    this.offset = new_offset;
-    /* add this's subsribers */
-    for(let index of this.indexes){
-        subscribers[index + new_offset].add(this);
-    }
-    need_cache_apply.push(this); 
-}
-
-function widget_apply_cache() {
-    for(let index of this.indexes){
-        /* dispatch current cache in newly opened page widgets */
-        let realindex = index+this.offset;
-        let cached_val = cache[realindex];
-        if(cached_val != undefined)
-            dispatch_value_to_widget(this, realindex, cached_val, cached_val);
-    }
-}
-
 function switch_visible_page(page_name) {
 
     let old_desc = page_desc[current_visible_page];
--- a/svghmi/widgets_common.ysl2	Sun May 10 16:32:19 2020 +0200
+++ b/svghmi/widgets_common.ysl2	Sun May 10 16:34:44 2020 +0200
@@ -73,6 +73,35 @@
             this.offset = 0;
             Object.keys(members).forEach(prop => this[prop]=members[prop]);
         }
+        unsub(){
+            /* remove subsribers */
+            for(let index of this.indexes){
+                let idx = index + this.offset;
+                subscribers[idx].delete(this);
+            }
+            this.offset = 0;
+        }
+
+        sub(new_offset=0){
+            /* set the offset because relative */
+            this.offset = new_offset;
+            /* add this's subsribers */
+            for(let index of this.indexes){
+                subscribers[index + new_offset].add(this);
+            }
+            need_cache_apply.push(this); 
+        }
+
+        apply_cache() {
+            for(let index of this.indexes){
+                /* dispatch current cache in newly opened page widgets */
+                let realindex = index+this.offset;
+                let cached_val = cache[realindex];
+                if(cached_val != undefined)
+                    dispatch_value_to_widget(this, realindex, cached_val, cached_val);
+            }
+        }
+
     }
     ||
 }
@@ -98,9 +127,6 @@
 
 // default : normal subscribing
 template "widget", mode="widget_subscribe" {
-    |     sub: subscribe,
-    |     unsub: unsubscribe,
-    |     apply_cache: widget_apply_cache,
 }
 // page aren't subscribers
 template "widget[@type='Page']", mode="widget_subscribe";