[IMP] qweb: add support for event capture

In this commit, we uses the "!" as suffix to designate an event that
should be captured.  This is inspired by the Vue source code.

This solves the issue of communicating additional information to the
underlying virtual dom.  However, this will most likely disappear when
we rewrite the vdom as a virtual block system.

closes #650
This commit is contained in:
Géry Debongnie
2020-02-20 11:27:47 +01:00
committed by aab-odoo
parent 2c01802b8e
commit b00188c1ce
8 changed files with 140 additions and 12 deletions
+24
View File
@@ -2192,6 +2192,30 @@ describe("other directives with t-component", () => {
expect(steps).toEqual(["click"]);
});
test("t-on with .capture modifier", async () => {
const steps: string[] = [];
class Child extends Component {
static template = xml`<div><span t-on-click="click">hey</span></div>`;
click() {
steps.push("click");
}
}
class ParentWidget extends Component {
static components = { Child };
static template = xml`<div><Child t-on-click.capture="capture"/></div>`;
capture() {
steps.push("captured");
}
}
const widget = new ParentWidget();
await widget.mount(fixture);
fixture.querySelector("span")!.click();
expect(env.qweb.templates[ParentWidget.template].fn.toString()).toMatchSnapshot();
expect(steps).toEqual(["captured", "click"]);
});
test("t-on on destroyed components", async () => {
const steps: string[] = [];
let child;