mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] app: support for arbitrary descriptors in env
Before this commit, when defining a getter in the env passed to the App, the value was read, losing the definition of the property. After this commit, declaring a getter in the env works as expected: the property stays a getter.
This commit is contained in:
committed by
Géry Debongnie
parent
c8db663869
commit
9d48bda227
+2
-1
@@ -44,7 +44,8 @@ export class App<T extends typeof Component = any> extends TemplateSet {
|
||||
console.info(DEV_MSG);
|
||||
}
|
||||
if (config.env) {
|
||||
this.env = Object.freeze(Object.assign({}, config.env));
|
||||
const descrs = Object.getOwnPropertyDescriptors(config.env);
|
||||
this.env = Object.freeze(Object.defineProperties({}, descrs));
|
||||
}
|
||||
if (config.translateFn) {
|
||||
this.translateFn = config.translateFn;
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`app App supports env with getters/setters 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div><block-text-0/> <block-text-1/></div>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let d1 = ctx['env'].someVal;
|
||||
let d2 = Object.keys(ctx['env'].services);
|
||||
return block1([d1, d2]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`app destroy remove the widget from the DOM 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { App, Component } from "../../src";
|
||||
import { status } from "../../src/component/status";
|
||||
import { xml } from "../../src/tags";
|
||||
import { makeTestFixture, snapshotEverything } from "../helpers";
|
||||
import { makeTestFixture, snapshotEverything, nextTick } from "../helpers";
|
||||
|
||||
let fixture: HTMLElement;
|
||||
|
||||
@@ -25,4 +25,30 @@ describe("app", () => {
|
||||
expect(document.contains(el)).toBe(false);
|
||||
expect(status(comp)).toBe("destroyed");
|
||||
});
|
||||
|
||||
test("App supports env with getters/setters", async () => {
|
||||
let someVal = "maggot";
|
||||
|
||||
const services: any = { serv1: "" };
|
||||
const env = {
|
||||
get someVal() {
|
||||
return someVal;
|
||||
},
|
||||
services,
|
||||
};
|
||||
|
||||
class SomeComponent extends Component {
|
||||
static template = xml`<div><t t-esc="env.someVal" /> <t t-esc="Object.keys(env.services)" /></div>`;
|
||||
}
|
||||
|
||||
const app = new App(SomeComponent);
|
||||
app.configure({ env });
|
||||
const comp = await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe("<div>maggot serv1</div>");
|
||||
someVal = "brain";
|
||||
services.serv2 = "";
|
||||
comp.render();
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe("<div>brain serv1,serv2</div>");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user