Defining a type for validation and then having to applyDefaults(props(..., type), type) is redundant.
It would be easier to be able to set it directly like props.static("properties", propType, {applyNestedDefault: true})
Current implementation
import { Component, mount, signal, props, xml, types as t, toRaw, applyDefaults } from "@odoo/owl";
const propType = t.object({
label: t.string().optional(),
title: t.string().optional("Default title"),
});
class Counter extends Component {
static template = xml`
<button t-on-click="this.increment">
<t t-out="this.properties.label"/>: <t t-out="this.value()"/>
<br/>
Title : <t t-out="this.properties.title"/>
</button>`;
// note that the prop is fixed: it cannot change!
properties = applyDefaults(props.static("properties", propType), propType);
value = signal(0);
increment() {
this.value.set(this.value() + 1);
}
setup() {
console.log(this.properties);
}
}
class Root extends Component {
static components = { Counter };
static template = xml`
<Counter properties="{label: 'Apples'}"/>`;
}
mount(Root, document.body, { templates: TEMPLATES, dev: true });
Defining a type for validation and then having to applyDefaults(props(..., type), type) is redundant.
It would be easier to be able to set it directly like
props.static("properties", propType, {applyNestedDefault: true})Current implementation