Skip to content

Commit fd3d68a

Browse files
committed
[IMP] awesome_owl: add a global counter
Add a callback to the buttons to create a global counter.
1 parent ad4da83 commit fd3d68a

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

awesome_owl/static/src/counter/counter.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@ import { Component, useState } from "@odoo/owl";
33

44
export class Counter extends Component {
55
static template = "awesome_owl.counter";
6+
static props = {
7+
onChange: { type: Function, optional: true }
8+
}
69

710
setup() {
8-
this.state = useState({ value:0});
11+
this.state = useState({ value: 0 });
912
}
1013

1114
increment() {
1215
this.state.value++;
16+
if (this.props.onChange) {
17+
this.props.onChange();
18+
}
1319
}
14-
}
20+
21+
}

awesome_owl/static/src/playground.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ export class Playground extends Component {
88
static template = "awesome_owl.playground";
99
static components = { Counter, Card };
1010

11-
someHTML = markup("<div class='text-primary'>some content</div>")
12-
someText = "<div class='text-primary'>some content</div>"
13-
11+
1412
setup() {
15-
this.state = useState({ value:0});
13+
this.someHTML = markup("<div class='text-primary'>some content</div>");
14+
this.someText = "<div class='text-primary'>some content</div>";
15+
this.sum = useState({ value: 0 });
1616
}
17-
18-
increment() {
19-
this.state.value++;
17+
18+
incrementSum() {
19+
this.sum.value++;
2020
}
2121
}

awesome_owl/static/src/playground.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
<t t-name="awesome_owl.playground">
55
<div class="p-3">
66
hello world
7-
<Counter />
7+
<Counter onChange.bind="incrementSum"/>
8+
<Counter onChange.bind="incrementSum"/>
9+
<Counter onChange.bind="incrementSum"/>
810
<Card title="'My Card'" content="someText"/>
911
<Card title="'Card 2'" content="someHTML"/>
12+
<t t-esc="this.sum.value.toString()"/>
1013
</div>
1114
</t>
1215

0 commit comments

Comments
 (0)