Files
owl/examples/todoapp/components/TodoApp.js
T
Géry Debongnie a7d2edd0c9 imp: qweb compiler now condenses whitespaces
This is a pretty big breaking change: the html output by qweb is now
different.

The main goal is to optimize the compiled templates:
- condense all consecutive whitespaces into a single spaces
- if possible, drop completely some text nodes, based on the following
  heuristic: if a text node is only composed of whitespaces, and
contains at least one linebreak, then it can be dropped.

This leads in my benchmark test to an improvement of about 10%, in
rendering speed and in memory consuption.

Note: whitespace here means anything that matches the \s regexp: newlines,
tabs, ...

close #8
2019-03-22 12:04:50 +01:00

60 lines
1.2 KiB
JavaScript

import { TodoItem } from "./TodoItem.js";
const { connect, Component } = odoo.core;
const ENTER_KEY = 13;
function mapStateToProps(state) {
return { todos: state.todos };
}
class TodoApp extends Component {
template = "todoapp";
widgets = { TodoItem };
state = { filter: "all" };
get visibleTodos() {
let todos = this.props.todos;
if (this.state.filter === "active") {
todos = todos.filter(t => !t.completed);
}
if (this.state.filter === "completed") {
todos = todos.filter(t => t.completed);
}
return todos;
}
get allChecked() {
return this.props.todos.every(todo => todo.completed);
}
get remaining() {
return this.props.todos.filter(todo => !todo.completed).length;
}
get remainingText() {
const items = this.remaining < 2 ? "item" : "items";
return ` ${items} left`;
}
addTodo(ev) {
if (ev.keyCode === ENTER_KEY) {
const title = ev.target.value;
if (title.trim()) {
this.env.store.dispatch("addTodo", title);
}
ev.target.value = "";
}
}
clearCompleted() {
this.env.store.dispatch("clearCompleted");
}
toggleAll() {
this.env.store.dispatch("toggleAll", !this.allChecked);
}
}
export default connect(mapStateToProps)(TodoApp);