Files
owl/demo/src/Counter.ts
T

27 lines
641 B
TypeScript
Raw Normal View History

2019-01-16 13:19:58 +01:00
import Widget from "../../src/core/widget";
const template = `
2019-01-21 15:46:29 +01:00
<div>
2019-01-16 13:19:58 +01:00
<button t-on-click="increment(-1)">-</button>
2019-01-21 14:38:44 +01:00
<span style="font-weight:bold">Value: <t t-esc="state.counter"/></span>
2019-01-16 13:19:58 +01:00
<button t-on-click="increment(1)">+</button>
</div>
`;
export default class Counter extends Widget {
name = "counter";
template = template;
state = {
counter: 0
};
2019-01-20 09:35:39 +01:00
constructor(parent: Widget | null, props: {initialState?: number}) {
2019-01-16 13:19:58 +01:00
super(parent);
2019-01-17 12:49:13 +01:00
this.state.counter = props.initialState || 0;
2019-01-16 13:19:58 +01:00
}
increment(delta: number) {
this.updateState({ counter: this.state.counter + delta });
}
}