mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
27 lines
606 B
TypeScript
27 lines
606 B
TypeScript
|
|
import Widget from "../../src/core/widget";
|
||
|
|
|
||
|
|
const template = `
|
||
|
|
<div t-debug="1">
|
||
|
|
<button t-on-click="increment(-1)">-</button>
|
||
|
|
<span>Value: <t t-esc="state.counter"/></span>
|
||
|
|
<button t-on-click="increment(1)">+</button>
|
||
|
|
</div>
|
||
|
|
`;
|
||
|
|
|
||
|
|
export default class Counter extends Widget {
|
||
|
|
name = "counter";
|
||
|
|
template = template;
|
||
|
|
state = {
|
||
|
|
counter: 0
|
||
|
|
};
|
||
|
|
|
||
|
|
constructor(parent: Widget, initialState?: number) {
|
||
|
|
super(parent);
|
||
|
|
this.state.counter = initialState || 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
increment(delta: number) {
|
||
|
|
this.updateState({ counter: this.state.counter + delta });
|
||
|
|
}
|
||
|
|
}
|