mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
fix context issue after loop t-foreach
This commit is contained in:
@@ -59,6 +59,12 @@ export class Context {
|
|||||||
return newContext;
|
return newContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
withInLoop(): Context {
|
||||||
|
const newContext = Object.create(this);
|
||||||
|
newContext.inLoop = true;
|
||||||
|
return newContext;
|
||||||
|
}
|
||||||
|
|
||||||
withCaller(node: Element): Context {
|
withCaller(node: Element): Context {
|
||||||
const newContext = Object.create(this);
|
const newContext = Object.create(this);
|
||||||
newContext.caller = node;
|
newContext.caller = node;
|
||||||
@@ -629,7 +635,7 @@ const forEachDirective: Directive = {
|
|||||||
priority: 10,
|
priority: 10,
|
||||||
atNodeEncounter({ node, qweb, ctx }): boolean {
|
atNodeEncounter({ node, qweb, ctx }): boolean {
|
||||||
ctx.rootContext.shouldProtectContext = true;
|
ctx.rootContext.shouldProtectContext = true;
|
||||||
ctx.inLoop = true;
|
ctx = ctx.withInLoop();
|
||||||
const elems = node.getAttribute("t-foreach")!;
|
const elems = node.getAttribute("t-foreach")!;
|
||||||
const name = node.getAttribute("t-as")!;
|
const name = node.getAttribute("t-as")!;
|
||||||
let arrayID = ctx.generateID();
|
let arrayID = ctx.generateID();
|
||||||
|
|||||||
@@ -698,3 +698,19 @@ describe("props evaluation (with t-props directive)", () => {
|
|||||||
expect(fixture.innerHTML).toBe("<div><span>42</span></div>");
|
expect(fixture.innerHTML).toBe("<div><span>42</span></div>");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("random stuff", () => {
|
||||||
|
test("widget after a t-foreach", async () => {
|
||||||
|
// this test makes sure that the foreach directive does not pollute sub
|
||||||
|
// context with the inLoop variable, which is then used in the t-widget
|
||||||
|
// directive as a key
|
||||||
|
class Test extends Widget<WEnv, {}> {
|
||||||
|
name = "test";
|
||||||
|
template = `<div><t t-foreach="2">txt</t><t t-widget="widget"/></div>`;
|
||||||
|
widgets = { widget: Widget };
|
||||||
|
}
|
||||||
|
const widget = new Test(env);
|
||||||
|
await widget.mount(fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("<div>txttxt<div></div></div>");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user