[FIX] components: ignore slot if no definition is given

closes #203
This commit is contained in:
Géry Debongnie
2019-06-24 12:57:15 +02:00
parent af6aca83a2
commit 3d2e2a1873
3 changed files with 32 additions and 2 deletions
+2
View File
@@ -705,11 +705,13 @@ QWeb.addDirective({
ctx.addLine(
`const slot${slotKey} = this.slots[context.__owl__.slotId + '_' + '${value}'];`
);
ctx.addIf(`slot${slotKey}`)
ctx.addLine(
`slot${slotKey}(context.__owl__.parent, Object.assign({}, extra, {parentNode: c${
ctx.parentNode
}}));`
);
ctx.closeIf();
return true;
}
});
+6 -2
View File
@@ -1083,12 +1083,16 @@ exports[`t-slot directive can define and call slots 2`] = `
var vn2 = h('div', p2, c2);
c1.push(vn2);
const slot3 = this.slots[context.__owl__.slotId + '_' + 'header'];
slot3(context.__owl__.parent, Object.assign({}, extra, {parentNode: c2}));
if (slot3) {
slot3(context.__owl__.parent, Object.assign({}, extra, {parentNode: c2}));
}
let c4 = [], p4 = {key:4};
var vn4 = h('div', p4, c4);
c1.push(vn4);
const slot5 = this.slots[context.__owl__.slotId + '_' + 'footer'];
slot5(context.__owl__.parent, Object.assign({}, extra, {parentNode: c4}));
if (slot5) {
slot5(context.__owl__.parent, Object.assign({}, extra, {parentNode: c4}));
}
return vn1;
}"
`;
+24
View File
@@ -3031,6 +3031,30 @@ describe("t-slot directive", () => {
);
});
test("missing slots are ignored", async () => {
env.qweb.addTemplates(`
<templates>
<div t-name="Parent">
<Dialog/>
</div>
<span t-name="Dialog">
<t t-slot="default"/>
<span>some content</span>
<t t-slot="footer"/>
</span>
</templates>
`);
class Dialog extends Widget {}
class Parent extends Widget {
components = { Dialog };
}
const parent = new Parent(env);
await parent.mount(fixture);
expect(fixture.innerHTML).toBe(
'<div><span><span>some content</span></span></div>'
);
});
});
describe("t-model directive", () => {