[IMP] qweb: the t-slot directive is now dynamic

It is useful for some kind of components to be able to use a completely
dynamic slot expression.
This commit is contained in:
Géry Debongnie
2020-10-30 12:12:08 +01:00
committed by aab-odoo
parent cb07c99d40
commit d83cfc12ee
4 changed files with 73 additions and 4 deletions
+3 -1
View File
@@ -1,4 +1,5 @@
import { VNode } from "../vdom/index";
import { INTERP_REGEXP } from "./compilation_context";
import { QWeb } from "./qweb";
/**
@@ -228,8 +229,9 @@ QWeb.addDirective({
priority: 80,
atNodeEncounter({ ctx, value, node, qweb }): boolean {
const slotKey = ctx.generateID();
const valueExpr = value.match(INTERP_REGEXP) ? ctx.interpolate(value) : `'${value}'`;
ctx.addLine(
`const slot${slotKey} = this.constructor.slots[context.__owl__.slotId + '_' + '${value}'];`
`const slot${slotKey} = this.constructor.slots[context.__owl__.slotId + '_' + ${valueExpr}];`
);
ctx.addIf(`slot${slotKey}`);
let parentNode = `c${ctx.parentNode}`;