mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
add support for ES6-like syntax for props
This commit is contained in:
@@ -844,6 +844,9 @@ const widgetDirective: Directive = {
|
|||||||
.split(",")
|
.split(",")
|
||||||
.map(p => {
|
.map(p => {
|
||||||
let [key, val] = p.split(":");
|
let [key, val] = p.split(":");
|
||||||
|
if (!val) {
|
||||||
|
val = key;
|
||||||
|
}
|
||||||
return `${key}: ${qweb._formatExpression(val)}`;
|
return `${key}: ${qweb._formatExpression(val)}`;
|
||||||
})
|
})
|
||||||
.join(",");
|
.join(",");
|
||||||
|
|||||||
+20
-3
@@ -1,4 +1,4 @@
|
|||||||
import { Component, WEnv } from "../src/component";
|
import { Component, Env } from "../src/component";
|
||||||
import {
|
import {
|
||||||
makeDeferred,
|
makeDeferred,
|
||||||
makeTestFixture,
|
makeTestFixture,
|
||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
// - env: a WEnv, necessary to create new widgets
|
// - env: a WEnv, necessary to create new widgets
|
||||||
|
|
||||||
let fixture: HTMLElement;
|
let fixture: HTMLElement;
|
||||||
let env: WEnv;
|
let env: Env;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = makeTestFixture();
|
fixture = makeTestFixture();
|
||||||
@@ -36,7 +36,7 @@ afterEach(() => {
|
|||||||
fixture.remove();
|
fixture.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
class Widget extends Component<WEnv, {}, {}> {}
|
class Widget extends Component<Env, any, any> {}
|
||||||
|
|
||||||
function children(w: Widget): Widget[] {
|
function children(w: Widget): Widget[] {
|
||||||
const childrenMap = w.__widget__.children;
|
const childrenMap = w.__widget__.children;
|
||||||
@@ -770,6 +770,23 @@ describe("props evaluation (with t-props directive)", () => {
|
|||||||
await widget.mount(fixture);
|
await widget.mount(fixture);
|
||||||
expect(fixture.innerHTML).toBe("<div><span>42</span></div>");
|
expect(fixture.innerHTML).toBe("<div><span>42</span></div>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("accept ES6-like syntax for props (with getters)", async () => {
|
||||||
|
class Child extends Widget {
|
||||||
|
inlineTemplate = `<span><t t-esc="props.greetings"/></span>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Widget {
|
||||||
|
inlineTemplate = `<div><t t-widget="child" t-props="{greetings}"/></div>`;
|
||||||
|
widgets = { child: Child };
|
||||||
|
get greetings() {
|
||||||
|
return `hello ${this.props.name}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const widget = new Parent(env, { name: "aaron" });
|
||||||
|
await widget.mount(fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("<div><span>hello aaron</span></div>");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("other directives with t-widget", () => {
|
describe("other directives with t-widget", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user