File tree Expand file tree Collapse file tree 6 files changed +23
-12
lines changed Expand file tree Collapse file tree 6 files changed +23
-12
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ export class Counter extends Component {
5
5
static props = {
6
6
value : { optional : true } ,
7
7
side_effect : { type : Function , optional : true }
8
- }
8
+ } ;
9
9
10
10
setup ( ) {
11
11
this . state = useState ( { value : this . props . value || 0 } ) ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export class Playground extends Component {
14
14
}
15
15
16
16
get sum ( ) {
17
- return this . state . val1 + this . state . val2
17
+ return this . state . val1 + this . state . val2 ;
18
18
}
19
19
20
20
}
Original file line number Diff line number Diff line change @@ -5,12 +5,14 @@ export class TodoItem extends Component {
5
5
static props = {
6
6
id : String ,
7
7
todo : { type : { description : String , isCompleted : Boolean } } ,
8
- toggleState : Function
8
+ toggleState : Function ,
9
+ removeTodo : Function
9
10
}
10
11
11
12
setup ( ) {
12
- this . id = this . props . id
13
- this . todo = useState ( this . props . todo )
14
- this . toggleState = this . props . toggleState
13
+ this . id = this . props . id ;
14
+ this . todo = useState ( this . props . todo ) ;
15
+ this . toggleState = this . props . toggleState ;
16
+ this . removeTodo = this . props . removeTodo ;
15
17
}
16
18
}
Original file line number Diff line number Diff line change 5
5
<div class =" todo_item-body" t-att-class =" {'text-muted text-decoration-line-through': this.todo.isCompleted}" >
6
6
<p class =" todo_item-text" >
7
7
<input type =" checkbox" t-att-checked =" this.todo.isCompleted" t-on-change =" this.toggleState" />
8
- <t t-esc =" this.id" />. <t t-out =" this.todo.description" />
8
+ <t t-esc =" this.id" />. <t t-out =" this.todo.description" /> < span class = " fa fa-remove " t-on-click = " this.removeTodo " />
9
9
</p >
10
10
</div >
11
11
</t >
Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ import { TodoItem } from "./todo_item";
3
3
import { useAutoFocus } from "../utils" ;
4
4
5
5
export class TodoList extends Component {
6
- static template = "awesome_owl.todo_list"
7
- static components = { TodoItem }
6
+ static template = "awesome_owl.todo_list" ;
7
+ static components = { TodoItem } ;
8
8
9
9
setup ( ) {
10
10
useAutoFocus ( "todo-input" ) ;
@@ -17,13 +17,17 @@ export class TodoList extends Component {
17
17
}
18
18
19
19
toggleState ( id ) {
20
- this . state . todos [ id ] . isCompleted = ! this . state . todos [ id ] . isCompleted
20
+ this . state . todos [ id ] . isCompleted = ! this . state . todos [ id ] . isCompleted ;
21
21
}
22
22
23
23
addTodo ( ev ) {
24
24
if ( ev . keyCode === 13 && ev . target . value != "" ) {
25
25
this . state . todos [ ++ this . state . lastId ] = { description : ev . target . value , isCompleted : false } ;
26
- ev . target . value = ""
26
+ ev . target . value = "" ;
27
27
}
28
28
}
29
+
30
+ removeTodo ( id ) {
31
+ delete this . state . todos [ id ] ;
32
+ }
29
33
}
Original file line number Diff line number Diff line change 11
11
t-ref =" todo-input"
12
12
/>
13
13
<t t-foreach =" Object.keys(this.state.todos)" t-as =" id" t-key =" id" >
14
- <TodoItem id =" id" todo =" this.state.todos[id]" toggleState.bind=" () => this.toggleState(id)" />
14
+ <TodoItem
15
+ id =" id"
16
+ todo =" this.state.todos[id]"
17
+ toggleState.bind=" () => this.toggleState(id)"
18
+ removeTodo.bind=" () => this.removeTodo(id)"
19
+ />
15
20
</t >
16
21
</div >
17
22
</div >
You can’t perform that action at this time.
0 commit comments