156 } |
156 } |
157 need_cache_apply.push(this); |
157 need_cache_apply.push(this); |
158 } |
158 } |
159 |
159 |
160 apply_cache() { |
160 apply_cache() { |
161 let dispatch = this.dispatch; |
|
162 if(dispatch == undefined) return; |
|
163 if(!this.unsubscribable) for(let index in this.indexes){ |
161 if(!this.unsubscribable) for(let index in this.indexes){ |
164 /* dispatch current cache in newly opened page widgets */ |
162 /* dispatch current cache in newly opened page widgets */ |
165 let realindex = this.get_variable_index(index); |
163 let realindex = this.get_variable_index(index); |
166 let cached_val = cache[realindex]; |
164 let cached_val = cache[realindex]; |
167 if(cached_val != undefined) |
165 if(cached_val != undefined) |
168 try { |
166 this._dispatch(cached_val, cached_val, index); |
169 dispatch.call(this, cached_val, cached_val, index); |
|
170 } catch(err) { |
|
171 console.log(err); |
|
172 } |
|
173 } |
167 } |
174 } |
168 } |
175 |
169 |
176 get_variable_index(varnum) { |
170 get_variable_index(varnum) { |
177 let index = this.indexes[varnum]; |
171 let index = this.indexes[varnum]; |
192 return apply_hmi_value(this.get_variable_index(0), new_val); |
186 return apply_hmi_value(this.get_variable_index(0), new_val); |
193 } |
187 } |
194 |
188 |
195 new_hmi_value(index, value, oldval) { |
189 new_hmi_value(index, value, oldval) { |
196 // TODO avoid searching, store index at sub() |
190 // TODO avoid searching, store index at sub() |
197 let dispatch = this.dispatch; |
|
198 if(dispatch == undefined) return; |
|
199 for(let i = 0; i < this.indexes.length; i++) { |
191 for(let i = 0; i < this.indexes.length; i++) { |
200 let refindex = this.get_variable_index(i); |
192 let refindex = this.get_variable_index(i); |
201 |
193 |
202 if(index == refindex) { |
194 if(index == refindex) { |
203 try { |
195 this._dispatch(value, oldval, i); |
204 dispatch.call(this, value, oldval, i); |
|
205 } catch(err) { |
|
206 console.log(err); |
|
207 } |
|
208 break; |
196 break; |
209 } |
197 } |
210 } |
198 } |
211 } |
199 } |
212 |
200 |
|
201 _dispatch(value, oldval, varnum) { |
|
202 let dispatch = this.dispatch; |
|
203 if(dispatch != undefined){ |
|
204 try { |
|
205 dispatch.call(this, value, oldval, varnum); |
|
206 } catch(err) { |
|
207 console.log(err); |
|
208 } |
|
209 } |
|
210 } |
|
211 |
213 _animate(){ |
212 _animate(){ |
214 this.animate(); |
213 this.animate(); |
215 this.pending_animate = false; |
214 this.pending_animate = false; |
216 } |
215 } |
217 |
216 |