Skip to content

Commit 64e4bad

Browse files
committed
[REF] awesome_owl: comply with feedback received.
1 parent 12800a7 commit 64e4bad

File tree

9 files changed

+41
-24
lines changed

9 files changed

+41
-24
lines changed

awesome_owl/static/src/card/card.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { Component, useState } from "@odoo/owl";
33
export class Card extends Component {
44
static template = "awesome_owl.card";
55
static props = {
6-
title: {type: String},
7-
slots: { type: Object, shape: { default: true } },
6+
title: String,
7+
slots: Object,
88
}
99

1010
setup() {
11-
this.isOpen = useState({ value: true });
11+
this.state = useState({ isOpen: true });
1212
}
1313

1414
toggle() {
15-
this.isOpen.value = !this.isOpen.value;
15+
this.state.isOpen = !this.state.isOpen;
1616
}
1717
}

awesome_owl/static/src/card/card.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<t t-esc="props.title"/>
99
<button class="btn" t-on-click="toggle">Toggle</button>
1010
</h5>
11-
<p class="card-text" t-if="this.isOpen.value">
11+
<p class="card-text" t-if="this.state.isOpen">
1212
<t t-slot="default"/>
1313
</p>
1414
</div>

awesome_owl/static/src/counter/counter.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { Component, useState } from "@odoo/owl";
22

33
export class Counter extends Component {
4-
static template = "awesome_owl.counter";
4+
static template = "awesome_owl.Counter";
55
static props = {
6-
callback: {type: Function},
6+
callback: {
7+
type: Function,
8+
optional: true,
9+
},
10+
};
11+
static defaultProps = {
12+
callback: () => {},
713
};
814

915
setup() {

awesome_owl/static/src/counter/counter.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<templates xml:space="preserve">
33

4-
<t t-name="awesome_owl.counter">
4+
<t t-name="awesome_owl.Counter">
55
<div class="card text-center">
66
<div class="card-body">
77
<h5 class="card-title">Counter</h5>

awesome_owl/static/src/playground.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<TodoList/>
77
</Card>
88
<Card title="'My Counter'">
9-
<Counter callback="() => {}"/>
9+
<Counter/>
1010
</Card>
1111
</t>
1212

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export class Todo {
2+
constructor(id, description) {
3+
this.id = id;
4+
this.description = description;
5+
this.isCompleted = false;
6+
}
7+
8+
setCompletion(isCompleted) {
9+
this.isCompleted = isCompleted;
10+
}
11+
}

awesome_owl/static/src/todolist/todoitem.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
/** @odoo-module **/
2-
31
import { Component } from "@odoo/owl";
2+
import { Todo } from "./todo";
43

54
export class TodoItem extends Component {
65
static template = "awesome_owl.todoitem";
76
static props = {
8-
todo: {type: Object, shape: {id: Number, description: String, isCompleted: Boolean }},
9-
toggleState: {type: Function},
10-
removeTodo: {type: Function},
7+
todo: Todo,
8+
toggleState: Function,
9+
removeTodo: Function,
1110
};
1211

1312
onChange() {

awesome_owl/static/src/todolist/todolist.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,34 @@
22

33
import { Component, useState } from "@odoo/owl";
44
import { TodoItem } from "./todoitem";
5+
import { Todo } from "./todo";
56
import { useAutofocus } from "../utils";
67

78
export class TodoList extends Component {
89
static template = "awesome_owl.todolist";
910
static components = { TodoItem };
1011

12+
setup() {
13+
this.todos = useState([]);
14+
this.sequence = 0;
15+
useAutofocus("new-todo");
16+
}
17+
1118
addTodo(event) {
1219
if (event.keyCode === 13 && event.target.value.trim() !== "") {
1320
this.sequence++;
14-
this.todos.push({id: this.sequence, description: event.target.value, isCompleted: false});
21+
this.todos.push(new Todo(this.sequence, event.target.value));
1522
event.target.value = "";
1623
}
1724
}
1825

1926
toggleState(id) {
2027
const todo = this.todos.find(t => t.id === id);
21-
if (todo) todo.isCompleted = !todo.isCompleted;
28+
if (todo) todo.setCompletion(!todo.isCompleted);
2229
}
2330

2431
removeTodo(id) {
2532
const index = this.todos.findIndex((elem) => elem.id === id);
26-
if (index >= 0) this.todos.splice(index, 1);
27-
}
28-
29-
setup() {
30-
this.todos = useState([]);
31-
this.sequence = 0;
32-
useAutofocus("new-todo");
33+
if (index !== -1) this.todos.splice(index, 1);
3334
}
3435
}

awesome_owl/static/src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ export function useAutofocus(refName) {
55
onMounted(() => {
66
ref.el.focus();
77
});
8-
}
8+
}

0 commit comments

Comments
 (0)