65 emit "preamble:widget-base-class" { |
65 emit "preamble:widget-base-class" { |
66 || |
66 || |
67 class Widget { |
67 class Widget { |
68 offset = 0; |
68 offset = 0; |
69 frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */ |
69 frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */ |
|
70 unsubscribable = false; |
70 constructor(elt_id,args,indexes,members){ |
71 constructor(elt_id,args,indexes,members){ |
71 this.element_id = elt_id; |
72 this.element_id = elt_id; |
72 this.element = id(elt_id); |
73 this.element = id(elt_id); |
73 this.args = args; |
74 this.args = args; |
74 this.indexes = indexes; |
75 this.indexes = indexes; |
75 Object.keys(members).forEach(prop => this[prop]=members[prop]); |
76 Object.keys(members).forEach(prop => this[prop]=members[prop]); |
76 } |
77 } |
77 |
78 |
78 unsub(){ |
79 unsub(){ |
79 /* remove subsribers */ |
80 /* remove subsribers */ |
80 for(let index of this.indexes){ |
81 if(!this.unsubscribable) for(let index of this.indexes){ |
81 let idx = index + this.offset; |
82 let idx = index + this.offset; |
82 subscribers[idx].delete(this); |
83 subscribers[idx].delete(this); |
83 } |
84 } |
84 this.offset = 0; |
85 this.offset = 0; |
85 } |
86 } |
86 |
87 |
87 sub(new_offset=0){ |
88 sub(new_offset=0){ |
88 /* set the offset because relative */ |
89 /* set the offset because relative */ |
89 this.offset = new_offset; |
90 this.offset = new_offset; |
90 /* add this's subsribers */ |
91 /* add this's subsribers */ |
91 for(let index of this.indexes){ |
92 if(!this.unsubscribable) for(let index of this.indexes){ |
92 subscribers[index + new_offset].add(this); |
93 subscribers[index + new_offset].add(this); |
93 } |
94 } |
94 need_cache_apply.push(this); |
95 need_cache_apply.push(this); |
95 } |
96 } |
96 |
97 |
97 apply_cache() { |
98 apply_cache() { |
98 for(let index of this.indexes){ |
99 if(!this.unsubscribable) for(let index of this.indexes){ |
99 /* dispatch current cache in newly opened page widgets */ |
100 /* dispatch current cache in newly opened page widgets */ |
100 let realindex = index+this.offset; |
101 let realindex = index+this.offset; |
101 let cached_val = cache[realindex]; |
102 let cached_val = cache[realindex]; |
102 if(cached_val != undefined) |
103 if(cached_val != undefined) |
103 dispatch_value_to_widget(this, realindex, cached_val, cached_val); |
104 dispatch_value_to_widget(this, realindex, cached_val, cached_val); |