diff -r 1e53d8b60ee9 -r 506fe9272660 svghmi/widgets_common.ysl2 --- 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";