beremiz

SVGHMI: factorize dispatch calling logic.
svghmi
2020-08-13, Edouard Tisserant
d454ed480c0f
Parents 48e7e336c052
Children d660b1b6bf4f
SVGHMI: factorize dispatch calling logic.
--- 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,10 +1141,6 @@
</xsl:text>
<xsl:text> apply_cache() {
</xsl:text>
- <xsl:text> let dispatch = this.dispatch;
-</xsl:text>
- <xsl:text> if(dispatch == undefined) return;
-</xsl:text>
<xsl:text> if(!this.unsubscribable) for(let index in this.indexes){
</xsl:text>
<xsl:text> /* dispatch current cache in newly opened page widgets */
@@ -1155,15 +1151,7 @@
</xsl:text>
<xsl:text> if(cached_val != undefined)
</xsl:text>
- <xsl:text> try {
-</xsl:text>
- <xsl:text> dispatch.call(this, cached_val, cached_val, index);
-</xsl:text>
- <xsl:text> } catch(err) {
-</xsl:text>
- <xsl:text> console.log(err);
-</xsl:text>
- <xsl:text> }
+ <xsl:text> this._dispatch(cached_val, cached_val, index);
</xsl:text>
<xsl:text> }
</xsl:text>
@@ -1213,10 +1201,6 @@
</xsl:text>
<xsl:text> // TODO avoid searching, store index at sub()
</xsl:text>
- <xsl:text> let dispatch = this.dispatch;
-</xsl:text>
- <xsl:text> if(dispatch == undefined) return;
-</xsl:text>
<xsl:text> for(let i = 0; i &lt; this.indexes.length; i++) {
</xsl:text>
<xsl:text> let refindex = this.get_variable_index(i);
@@ -1225,15 +1209,7 @@
</xsl:text>
<xsl:text> if(index == refindex) {
</xsl:text>
- <xsl:text> try {
-</xsl:text>
- <xsl:text> dispatch.call(this, value, oldval, i);
-</xsl:text>
- <xsl:text> } catch(err) {
-</xsl:text>
- <xsl:text> console.log(err);
-</xsl:text>
- <xsl:text> }
+ <xsl:text> this._dispatch(value, oldval, i);
</xsl:text>
<xsl:text> break;
</xsl:text>
@@ -1245,6 +1221,28 @@
</xsl:text>
<xsl:text>
</xsl:text>
+ <xsl:text> _dispatch(value, oldval, varnum) {
+</xsl:text>
+ <xsl:text> let dispatch = this.dispatch;
+</xsl:text>
+ <xsl:text> if(dispatch != undefined){
+</xsl:text>
+ <xsl:text> try {
+</xsl:text>
+ <xsl:text> dispatch.call(this, value, oldval, varnum);
+</xsl:text>
+ <xsl:text> } catch(err) {
+</xsl:text>
+ <xsl:text> console.log(err);
+</xsl:text>
+ <xsl:text> }
+</xsl:text>
+ <xsl:text> }
+</xsl:text>
+ <xsl:text> }
+</xsl:text>
+ <xsl:text>
+</xsl:text>
<xsl:text> _animate(){
</xsl:text>
<xsl:text> this.animate();
--- 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;