mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] component: support dynamic t-props
It is useful in some rare situations. closes #144
This commit is contained in:
@@ -63,7 +63,6 @@ class WidgetA extends Widget {
|
||||
static components = { b: WidgetB };
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Tests
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -900,7 +899,6 @@ describe("destroy method", () => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const parent = new Parent(env);
|
||||
await parent.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe("<div><span><button>click</button></span></div>");
|
||||
@@ -2243,7 +2241,6 @@ describe("random stuff/miscellaneous", () => {
|
||||
name = "A";
|
||||
}
|
||||
|
||||
|
||||
const a = new A(env);
|
||||
await a.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe(`<div>A<div>B</div><div>C<div>D</div><div>E</div></div></div>`);
|
||||
@@ -4317,7 +4314,7 @@ describe("dynamic root nodes", () => {
|
||||
</templates>
|
||||
`);
|
||||
class TestWidget extends Widget {
|
||||
state = {flag: true};
|
||||
state = { flag: true };
|
||||
}
|
||||
|
||||
const widget = new TestWidget(env);
|
||||
@@ -4344,8 +4341,8 @@ describe("dynamic root nodes", () => {
|
||||
class ChildA extends Widget {}
|
||||
class ChildB extends Widget {}
|
||||
class TestWidget extends Widget {
|
||||
static components = {ChildA, ChildB};
|
||||
state = {flag: true};
|
||||
static components = { ChildA, ChildB };
|
||||
state = { flag: true };
|
||||
}
|
||||
|
||||
const widget = new TestWidget(env);
|
||||
@@ -4357,5 +4354,38 @@ describe("dynamic root nodes", () => {
|
||||
|
||||
expect(fixture.innerHTML).toBe("<div>abc</div>");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
describe("dynamic t-props", () => {
|
||||
test("basic use", async () => {
|
||||
expect.assertions(4);
|
||||
env.qweb.addTemplates(`
|
||||
<templates>
|
||||
<span t-name="Child">
|
||||
<t t-esc="props.a + props.b"/>
|
||||
</span>
|
||||
<div t-name="Parent">
|
||||
<Child t-props="some.obj"/>
|
||||
</div>
|
||||
</templates>
|
||||
`);
|
||||
class Child extends Widget {
|
||||
constructor(parent, props) {
|
||||
super(parent, props);
|
||||
expect(props).toEqual({ a: 1, b: 2 });
|
||||
expect(props).not.toBe(widget.some.obj);
|
||||
}
|
||||
}
|
||||
class Parent extends Widget {
|
||||
static components = { Child };
|
||||
|
||||
some = { obj: { a: 1, b: 2 } };
|
||||
}
|
||||
|
||||
const widget = new Parent(env);
|
||||
await widget.mount(fixture);
|
||||
|
||||
expect(fixture.innerHTML).toBe("<div><span>3</span></div>");
|
||||
expect(env.qweb.templates.Parent.fn.toString()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user