mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
properly call willunmount and destroy hooks
This commit is contained in:
@@ -6,6 +6,8 @@ const template = `<div class="o_clock"><t t-esc="state.currentTime"/></div>`;
|
||||
export class Clock extends Widget<Env> {
|
||||
name = "clock";
|
||||
template = template;
|
||||
interval: any | undefined;
|
||||
|
||||
state = {
|
||||
currentTime: ""
|
||||
};
|
||||
@@ -15,9 +17,12 @@ export class Clock extends Widget<Env> {
|
||||
}
|
||||
|
||||
mounted() {
|
||||
setInterval(this.updateTime.bind(this), 500);
|
||||
this.interval = setInterval(this.updateTime.bind(this), 500);
|
||||
}
|
||||
|
||||
willUnmount() {
|
||||
clearInterval(this.interval);
|
||||
}
|
||||
updateTime() {
|
||||
this.updateState({
|
||||
currentTime: new Date().toLocaleTimeString()
|
||||
|
||||
Reference in New Issue
Block a user