# HG changeset patch # User Edouard Tisserant # Date 1597311459 -7200 # Node ID d454ed480c0f92429483cf98e8f921fbcf4cc971 # Parent 48e7e336c0528b77ac394221f4269fecf804ba53 SVGHMI: factorize dispatch calling logic. diff -r 48e7e336c052 -r d454ed480c0f svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Thu Aug 13 11:30:18 2020 +0200 +++ b/svghmi/gen_index_xhtml.xslt Thu Aug 13 11:37:39 2020 +0200 @@ -1141,29 +1141,101 @@ apply_cache() { + if(!this.unsubscribable) for(let index in this.indexes){ + + /* dispatch current cache in newly opened page widgets */ + + let realindex = this.get_variable_index(index); + + let cached_val = cache[realindex]; + + if(cached_val != undefined) + + this._dispatch(cached_val, cached_val, index); + + } + + } + + + + get_variable_index(varnum) { + + let index = this.indexes[varnum]; + + if(typeof(index) == "string"){ + + index = page_local_index(index, this.container_id); + + } else { + + if(this.relativeness[varnum]){ + + index += this.offset; + + } + + } + + return index; + + } + + change_hmi_value(index,opstr) { + + return change_hmi_value(this.get_variable_index(index), opstr); + + } + + + + apply_hmi_value(index, new_val) { + + return apply_hmi_value(this.get_variable_index(0), new_val); + + } + + + + new_hmi_value(index, value, oldval) { + + // TODO avoid searching, store index at sub() + + for(let i = 0; i < this.indexes.length; i++) { + + let refindex = this.get_variable_index(i); + + + + if(index == refindex) { + + this._dispatch(value, oldval, i); + + break; + + } + + } + + } + + + + _dispatch(value, oldval, varnum) { + let dispatch = this.dispatch; - if(dispatch == undefined) return; - - if(!this.unsubscribable) for(let index in this.indexes){ - - /* dispatch current cache in newly opened page widgets */ - - let realindex = this.get_variable_index(index); - - let cached_val = cache[realindex]; - - if(cached_val != undefined) - - try { - - dispatch.call(this, cached_val, cached_val, index); - - } catch(err) { - - console.log(err); - - } + if(dispatch != undefined){ + + try { + + dispatch.call(this, value, oldval, varnum); + + } catch(err) { + + console.log(err); + + } } @@ -1171,80 +1243,6 @@ - get_variable_index(varnum) { - - let index = this.indexes[varnum]; - - if(typeof(index) == "string"){ - - index = page_local_index(index, this.container_id); - - } else { - - if(this.relativeness[varnum]){ - - index += this.offset; - - } - - } - - return index; - - } - - change_hmi_value(index,opstr) { - - return change_hmi_value(this.get_variable_index(index), opstr); - - } - - - - apply_hmi_value(index, new_val) { - - return apply_hmi_value(this.get_variable_index(0), new_val); - - } - - - - new_hmi_value(index, value, oldval) { - - // TODO avoid searching, store index at sub() - - let dispatch = this.dispatch; - - if(dispatch == undefined) return; - - for(let i = 0; i < this.indexes.length; i++) { - - let refindex = this.get_variable_index(i); - - - - if(index == refindex) { - - try { - - dispatch.call(this, value, oldval, i); - - } catch(err) { - - console.log(err); - - } - - break; - - } - - } - - } - - - _animate(){ this.animate(); diff -r 48e7e336c052 -r d454ed480c0f svghmi/widgets_common.ysl2 --- a/svghmi/widgets_common.ysl2 Thu Aug 13 11:30:18 2020 +0200 +++ b/svghmi/widgets_common.ysl2 Thu Aug 13 11:37:39 2020 +0200 @@ -158,18 +158,12 @@ } apply_cache() { - let dispatch = this.dispatch; - if(dispatch == undefined) return; if(!this.unsubscribable) for(let index in this.indexes){ /* dispatch current cache in newly opened page widgets */ let realindex = this.get_variable_index(index); let cached_val = cache[realindex]; if(cached_val != undefined) - try { - dispatch.call(this, cached_val, cached_val, index); - } catch(err) { - console.log(err); - } + this._dispatch(cached_val, cached_val, index); } } @@ -194,22 +188,27 @@ new_hmi_value(index, value, oldval) { // TODO avoid searching, store index at sub() - let dispatch = this.dispatch; - if(dispatch == undefined) return; for(let i = 0; i < this.indexes.length; i++) { let refindex = this.get_variable_index(i); if(index == refindex) { - try { - dispatch.call(this, value, oldval, i); - } catch(err) { - console.log(err); - } + this._dispatch(value, oldval, i); break; } } } + _dispatch(value, oldval, varnum) { + let dispatch = this.dispatch; + if(dispatch != undefined){ + try { + dispatch.call(this, value, oldval, varnum); + } catch(err) { + console.log(err); + } + } + } + _animate(){ this.animate(); this.pending_animate = false;