mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] examples: update benchmarks/todoapp to new code
This commit is contained in:
@@ -36,16 +36,12 @@ export class App extends owl.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setMessageCount(n) {
|
setMessageCount(n) {
|
||||||
this.updateState({
|
this.state.messages = messages.slice(0, n);
|
||||||
messages: messages.slice(0, n)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeMessage(data) {
|
removeMessage(data) {
|
||||||
const index = messages.findIndex(m => m.id === data.id);
|
const index = messages.findIndex(m => m.id === data.id);
|
||||||
const n = this.state.messages.length;
|
this.state.messages.splice(index, 1);
|
||||||
messages.splice(index, 1);
|
|
||||||
this.updateState({ messages: messages.slice(0, n - 1) });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
increment(delta) {
|
increment(delta) {
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ export class Counter extends owl.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
increment(delta) {
|
increment(delta) {
|
||||||
this.updateState({ counter: this.state.counter + delta });
|
this.state.counter += delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,10 @@ class TodoApp extends Component {
|
|||||||
toggleAll() {
|
toggleAll() {
|
||||||
this.env.store.dispatch("toggleAll", !this.allChecked);
|
this.env.store.dispatch("toggleAll", !this.allChecked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setFilter(filter) {
|
||||||
|
this.state.filter = filter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps)(TodoApp);
|
export default connect(mapStateToProps)(TodoApp);
|
||||||
|
|||||||
@@ -15,10 +15,12 @@ export class TodoItem extends owl.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async editTodo() {
|
async editTodo() {
|
||||||
await this.updateState({ isEditing: true });
|
this.state.isEditing = true;
|
||||||
this.refs.input.value = "";
|
setTimeout(() => {
|
||||||
this.refs.input.focus();
|
this.refs.input.value = "";
|
||||||
this.refs.input.value = this.props.title;
|
this.refs.input.focus();
|
||||||
|
this.refs.input.value = this.props.title;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleKeyup(ev) {
|
handleKeyup(ev) {
|
||||||
@@ -27,7 +29,7 @@ export class TodoItem extends owl.Component {
|
|||||||
}
|
}
|
||||||
if (ev.keyCode === ESC_KEY) {
|
if (ev.keyCode === ESC_KEY) {
|
||||||
ev.target.value = this.props.title;
|
ev.target.value = this.props.title;
|
||||||
this.updateState({ isEditing: false });
|
this.state.isEditing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@ export class TodoItem extends owl.Component {
|
|||||||
id: this.props.id,
|
id: this.props.id,
|
||||||
title: value
|
title: value
|
||||||
});
|
});
|
||||||
this.updateState({ isEditing: false });
|
this.state.isEditing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,13 +27,13 @@
|
|||||||
</span>
|
</span>
|
||||||
<ul class="filters">
|
<ul class="filters">
|
||||||
<li>
|
<li>
|
||||||
<a href="#/all" t-on-click="updateState({filter:'all'})" t-att-class="{selected: state.filter === 'all'}">All</a>
|
<a href="#/all" t-on-click="setFilter('all')" t-att-class="{selected: state.filter === 'all'}">All</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="#/active" t-on-click="updateState({filter:'active'})" t-att-class="{selected: state.filter === 'active'}">Active</a>
|
<a href="#/active" t-on-click="setFilter('active')" t-att-class="{selected: state.filter === 'active'}">Active</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="#/completed" t-on-click="updateState({filter:'completed'})" t-att-class="{selected: state.filter === 'completed'}">Completed</a>
|
<a href="#/completed" t-on-click="setFilter('completed')" t-att-class="{selected: state.filter === 'completed'}">Completed</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<button class="clear-completed" t-if="props.todos.length gt remaining" t-on-click="clearCompleted">
|
<button class="clear-completed" t-if="props.todos.length gt remaining" t-on-click="clearCompleted">
|
||||||
|
|||||||
Reference in New Issue
Block a user