mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] component: defaultProps application
We re-add the application of defaultProps. Note that the application is done twice in dev mode.
This commit is contained in:
committed by
Géry Debongnie
parent
6e0834ce5e
commit
c3695ec8db
@@ -1,5 +1,22 @@
|
||||
import { Component } from "./component";
|
||||
|
||||
/**
|
||||
* Apply default props (only top level).
|
||||
*
|
||||
* Note that this method does modify in place the props
|
||||
*/
|
||||
export function applyDefaultProps(props: { [key: string]: any }, ComponentClass: typeof Component) {
|
||||
const defaultProps = (ComponentClass as any).defaultProps
|
||||
if (defaultProps) {
|
||||
for (let propName in defaultProps) {
|
||||
if (props![propName] === undefined) {
|
||||
props![propName] = defaultProps[propName];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Prop validation helper
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -17,6 +34,8 @@ export const validateProps = function (name: string | typeof Component, props: a
|
||||
const ComponentClass =
|
||||
typeof name !== "string" ? name : parent.constructor.components[name as string];
|
||||
|
||||
applyDefaultProps(props, ComponentClass);
|
||||
|
||||
const propsDef = (<any>ComponentClass).props;
|
||||
if (propsDef instanceof Array) {
|
||||
// list of strings (prop names)
|
||||
|
||||
Reference in New Issue
Block a user