mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] qweb, blockdom, components: t-on with modifiers
supported modifiers: capture, prevent, stop, self.
This commit is contained in:
committed by
Aaron Bohy
parent
2ae0149adb
commit
4cceb239dd
@@ -468,12 +468,17 @@ export class QWebCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
generateHandlerCode(handler: string, event: string = ""): string {
|
||||
generateHandlerCode(rawEvent: string, handler: string): string {
|
||||
let args: string = "";
|
||||
const name: string = handler.replace(/\(.*\)/, function (_args) {
|
||||
args = _args.slice(1, -1);
|
||||
return "";
|
||||
});
|
||||
const modifiers = rawEvent.split(".").slice(1).map(m => `"${m}"`);
|
||||
let modifiersCode = "";
|
||||
if (modifiers.length) {
|
||||
modifiersCode = `${modifiers.join(",")}, `;
|
||||
}
|
||||
const isMethodCall = name.match(FNAMEREGEXP);
|
||||
if (isMethodCall) {
|
||||
let handlerFn: string;
|
||||
@@ -484,15 +489,11 @@ export class QWebCompiler {
|
||||
} else {
|
||||
handlerFn = `'${name}'`;
|
||||
}
|
||||
return `[${event ? `\`${event}\`` + ", " : ""}ctx, ${handlerFn!}]`;
|
||||
return `[${modifiersCode}ctx, ${handlerFn!}]`;
|
||||
} else {
|
||||
let code = this.captureExpression(handler);
|
||||
code = `{const res = (() => { return ${code} })(); if (typeof res === 'function') { res(e) }}`;
|
||||
let handlerFn = `(e) => ${code}`;
|
||||
if (event) {
|
||||
handlerFn = `[\`${event}\`, ${handlerFn}]`;
|
||||
}
|
||||
return handlerFn;
|
||||
return `[${modifiersCode}(e) => ${code}]`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -528,7 +529,7 @@ export class QWebCompiler {
|
||||
|
||||
// event handlers
|
||||
for (let ev in ast.on) {
|
||||
const name = this.generateHandlerCode(ast.on[ev]);
|
||||
const name = this.generateHandlerCode(ev, ast.on[ev]);
|
||||
const idx = block!.insertData(name);
|
||||
attrs[`block-handler-${idx}`] = ev;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user