mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] directive: make props override t-props
Before this commit, props and t-props were computed like `Object.assign(props, t_props)`. Now, it computes like `Object.assign(t_props, props)` so props will override t-props. closes https://github.com/odoo/owl/issues/886
This commit is contained in:
committed by
Géry Debongnie
parent
7ebe0da962
commit
d08ea63565
@@ -336,7 +336,7 @@ QWeb.addDirective({
|
|||||||
}
|
}
|
||||||
if (hasDynamicProps) {
|
if (hasDynamicProps) {
|
||||||
const dynamicProp = ctx.formatExpression(node.getAttribute("t-props")!);
|
const dynamicProp = ctx.formatExpression(node.getAttribute("t-props")!);
|
||||||
ctx.addLine(`let props${componentID} = Object.assign({${propStr}}, ${dynamicProp});`);
|
ctx.addLine(`let props${componentID} = Object.assign({}, ${dynamicProp}, {${propStr}});`);
|
||||||
} else {
|
} else {
|
||||||
ctx.addLine(`let props${componentID} = {${propStr}};`);
|
ctx.addLine(`let props${componentID} = {${propStr}};`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -467,7 +467,7 @@ exports[`dynamic t-props basic use 1`] = `
|
|||||||
let vn1 = h('div', p1, c1);
|
let vn1 = h('div', p1, c1);
|
||||||
// Component 'Child'
|
// Component 'Child'
|
||||||
let w2 = '__3__' in parent.__owl__.cmap ? parent.__owl__.children[parent.__owl__.cmap['__3__']] : false;
|
let w2 = '__3__' in parent.__owl__.cmap ? parent.__owl__.children[parent.__owl__.cmap['__3__']] : false;
|
||||||
let props2 = Object.assign({}, scope['some'].obj);
|
let props2 = Object.assign({}, scope['some'].obj, {});
|
||||||
if (w2 && w2.__owl__.currentFiber && !w2.__owl__.vnode) {
|
if (w2 && w2.__owl__.currentFiber && !w2.__owl__.vnode) {
|
||||||
w2.destroy();
|
w2.destroy();
|
||||||
w2 = false;
|
w2 = false;
|
||||||
|
|||||||
@@ -4040,6 +4040,30 @@ describe("dynamic t-props", () => {
|
|||||||
expect(fixture.innerHTML).toBe("<div><span>3</span></div>");
|
expect(fixture.innerHTML).toBe("<div><span>3</span></div>");
|
||||||
expect(env.qweb.templates[Parent.template].fn.toString()).toMatchSnapshot();
|
expect(env.qweb.templates[Parent.template].fn.toString()).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-props with props", async () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`<div />`;
|
||||||
|
setup() {
|
||||||
|
expect(this.props).toEqual({ a: 1, b: 2, c: "c" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<div>
|
||||||
|
<Child t-props="props" a="1" b="2" />
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
static components = { Child };
|
||||||
|
|
||||||
|
props = { a: "a", c: "c" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const widget = new Parent();
|
||||||
|
await widget.mount(fixture);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("support svg components", () => {
|
describe("support svg components", () => {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ exports[`RouteComponent can render simple cases 1`] = `
|
|||||||
let w4 = k5 in parent.__owl__.cmap ? parent.__owl__.children[parent.__owl__.cmap[k5]] : false;
|
let w4 = k5 in parent.__owl__.cmap ? parent.__owl__.children[parent.__owl__.cmap[k5]] : false;
|
||||||
let vn6 = {};
|
let vn6 = {};
|
||||||
result = vn6;
|
result = vn6;
|
||||||
let props4 = Object.assign({}, scope['env'].router.currentParams);
|
let props4 = Object.assign({}, scope['env'].router.currentParams, {});
|
||||||
if (w4 && w4.__owl__.currentFiber && !w4.__owl__.vnode) {
|
if (w4 && w4.__owl__.currentFiber && !w4.__owl__.vnode) {
|
||||||
w4.destroy();
|
w4.destroy();
|
||||||
w4 = false;
|
w4 = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user