[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
@@ -2425,6 +2425,26 @@ exports[`t-on t-on combined with t-raw 1`] = `
}"
`;
exports[`t-on t-on with .capture modifier 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"test\\"
let utils = this.constructor.utils;
let h = this.h;
let c1 = [], p1 = {key:1,on:{}};
let vn1 = h('div', p1, c1);
extra.handlers['!click__2__'] = extra.handlers['!click__2__'] || function (e) {if (!context.__owl__.isMounted){return}utils.getComponent(context)['onCapture'](e);};
p1.on['!click'] = extra.handlers['!click__2__'];
let c3 = [], p3 = {key:3,on:{}};
let vn3 = h('button', p3, c3);
c1.push(vn3);
extra.handlers['click__4__'] = extra.handlers['click__4__'] || function (e) {if (!context.__owl__.isMounted){return}utils.getComponent(context)['doSomething'](e);};
p3.on['click'] = extra.handlers['click__4__'];
c3.push({text: \`Button\`});
return vn1;
}"
`;
exports[`t-on t-on with empty handler (only modifiers) 1`] = `
"function anonymous(context, extra
) {
+25
View File
@@ -1627,6 +1627,31 @@ describe("t-on", () => {
expect(steps).toEqual(["onClick"]);
});
test("t-on with .capture modifier", () => {
expect.assertions(2);
qweb.addTemplate(
"test",
`<div t-on-click.capture="onCapture">
<button t-on-click="doSomething">Button</button>
</div>`
);
const steps: string[] = [];
const owner = {
onCapture() {
steps.push("captured");
},
doSomething() {
steps.push("normal");
}
};
const node = renderToDOM(qweb, "test", owner, { handlers: [] });
const button = (<HTMLElement>node).getElementsByTagName("button")[0];
button.click();
expect(steps).toEqual(["captured", "normal"]);
});
});
describe("t-ref", () => {