mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] hooks: useSubEnv will not erase previous useChildSubEnv
This commit is contained in:
+1
-2
@@ -45,9 +45,8 @@ function extendEnv(currentEnv: Object, extension: Object): Object {
|
||||
*/
|
||||
export function useSubEnv(envExtension: Env) {
|
||||
const node = getCurrent()!;
|
||||
const newEnv = extendEnv(node.component.env as any, envExtension);
|
||||
node.component.env = extendEnv(node.component.env as any, envExtension);
|
||||
node.childEnv = newEnv;
|
||||
useChildSubEnv(envExtension);
|
||||
}
|
||||
|
||||
export function useChildSubEnv(envExtension: Env) {
|
||||
|
||||
@@ -103,6 +103,37 @@ exports[`hooks mounted callbacks should be called in reverse order from willUnmo
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`hooks parent and child env (with useChildSubEnv then useSubEnv) 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let b2 = text(ctx['env'].val);
|
||||
let b3 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
||||
return multi([b2, b3]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`hooks parent and child env (with useChildSubEnv then useSubEnv) 2`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
|
||||
let block2 = createBlock(\`<div><block-text-0/></div>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let b2;
|
||||
if (ctx['env'].hasParent) {
|
||||
let txt1 = ctx['env'].val;
|
||||
b2 = block2([txt1]);
|
||||
}
|
||||
return multi([b2]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`hooks parent and child env (with useChildSubEnv) 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -322,6 +322,24 @@ describe("hooks", () => {
|
||||
expect(fixture.innerHTML).toBe("3<div>5</div>");
|
||||
});
|
||||
|
||||
test("parent and child env (with useChildSubEnv then useSubEnv)", async () => {
|
||||
class Child extends Component {
|
||||
static template = xml`<div t-if="env.hasParent"><t t-esc="env.val"/></div>`;
|
||||
}
|
||||
|
||||
class Parent extends Component {
|
||||
static template = xml`<t t-esc="env.val"/><Child/>`;
|
||||
static components = { Child };
|
||||
setup() {
|
||||
useChildSubEnv({ hasParent: true });
|
||||
useSubEnv({ val: 5 });
|
||||
}
|
||||
}
|
||||
const env = { val: 3 };
|
||||
await mount(Parent, fixture, { env });
|
||||
expect(fixture.innerHTML).toBe("5<div>5</div>");
|
||||
});
|
||||
|
||||
test("can use onWillStart, onWillUpdateProps", async () => {
|
||||
const steps: string[] = [];
|
||||
async function slow(): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user