[FIX] component: do not validate props twice

it is not useful to do it in the component directive, especially since
it is done in the constructor, and the default props are not applied.

closes #379
This commit is contained in:
Géry Debongnie
2019-10-22 21:27:28 +02:00
committed by aab-odoo
parent be556a970e
commit 13128ed425
3 changed files with 18 additions and 4 deletions
-3
View File
@@ -412,9 +412,6 @@ QWeb.addDirective({
ctx.addLine( ctx.addLine(
`if (!W${componentID}) {throw new Error('Cannot find the definition of component "' + componentKey${componentID} + '"')}` `if (!W${componentID}) {throw new Error('Cannot find the definition of component "' + componentKey${componentID} + '"')}`
); );
if (QWeb.dev) {
ctx.addLine(`utils.validateProps(W${componentID}, props${componentID})`);
}
ctx.addLine(`w${componentID} = new W${componentID}(parent, props${componentID});`); ctx.addLine(`w${componentID} = new W${componentID}(parent, props${componentID});`);
ctx.addLine(`parent.__owl__.cmap[${templateId}] = w${componentID}.__owl__.id;`); ctx.addLine(`parent.__owl__.cmap[${templateId}] = w${componentID}.__owl__.id;`);
@@ -33,7 +33,6 @@ exports[`props validation props are validated in dev mode (code snapshot) 1`] =
let componentKey4 = \`Child\`; let componentKey4 = \`Child\`;
let W4 = context.constructor.components[componentKey4] || QWeb.components[componentKey4]|| context['Child']; let W4 = context.constructor.components[componentKey4] || QWeb.components[componentKey4]|| context['Child'];
if (!W4) {throw new Error('Cannot find the definition of component \\"' + componentKey4 + '\\"')} if (!W4) {throw new Error('Cannot find the definition of component \\"' + componentKey4 + '\\"')}
utils.validateProps(W4, props4)
w4 = new W4(parent, props4); w4 = new W4(parent, props4);
parent.__owl__.cmap[templateId4] = w4.__owl__.id; parent.__owl__.cmap[templateId4] = w4.__owl__.id;
def3 = w4.__prepare(extra.fiber, undefined, undefined); def3 = w4.__prepare(extra.fiber, undefined, undefined);
+18
View File
@@ -352,4 +352,22 @@ describe("default props", () => {
expect(w.props.p).toBe(4); expect(w.props.p).toBe(4);
expect(fixture.innerHTML).toMatchSnapshot(); expect(fixture.innerHTML).toMatchSnapshot();
}); });
test("can set default required boolean values", async () => {
class TestWidget extends Widget {
static props = ["p", "q"];
static defaultProps = { p: true, q: false };
static template = xml`<span><t t-if="props.p">hey</t><t t-if="!props.q">hey</t></span>`;
}
class App extends Widget {
static template = xml`<div><TestWidget/></div>`;
static components = { TestWidget };
}
const w = new App(env, {});
await w.mount(fixture);
expect(fixture.innerHTML).toBe('<div><span>heyhey</span></div>')
});
}); });