fix tricky issue with sub widgets modifying el

This commit is contained in:
Géry Debongnie
2019-01-26 08:40:09 +01:00
parent a47a65d333
commit bfa76e9de5
4 changed files with 43 additions and 17 deletions
+7 -8
View File
@@ -6,12 +6,13 @@ import { Counter } from "./counter";
const template = `
<div class="o_discuss">
<span>DISCUSS!!</span>
<button t-on-click="resetCounter">Reset</button>
<button t-on-click="resetCounterAsync">Reset in 3s</button>
<button t-on-click="toggle">Toggle Counter</button>
<button t-on-click="resetCounter">Reset first counter</button>
<button t-on-click="resetCounterAsync">Reset counter 2 in 3s</button>
<button t-on-click="toggle">Toggle Clock/counters</button>
<input/>
<t t-if="state.validcounter">
<t t-widget="Counter" t-ref="counter" t-props="{initialState:4}"/>
<t t-widget="Counter" t-ref="counter2" t-props="{initialState:400}"/>
</t>
<t t-else="1">
<t t-widget="Clock"/>
@@ -35,15 +36,13 @@ export class Discuss extends Widget<Env> {
resetCounterAsync(ev: MouseEvent) {
setTimeout(() => {
if (this.refs.counter instanceof Counter) {
this.refs.counter.updateState({ counter: 3 });
if (this.refs.counter2 instanceof Counter) {
this.refs.counter2.updateState({ counter: 300 });
}
}, 3000);
}
toggle() {
if (this.refs.counter instanceof Counter) {
this.updateState({ validcounter: !this.state.validcounter });
}
this.updateState({ validcounter: !this.state.validcounter });
}
}