diff --git a/js/src/common/Component.ts b/js/src/common/Component.ts index ef4fb3490..2529bee05 100644 --- a/js/src/common/Component.ts +++ b/js/src/common/Component.ts @@ -11,7 +11,11 @@ export type ComponentProps = { export default class Component { element: HTMLElement; - props = {}; + props: T; + + constructor(props: T = {}) { + this.props = props; + } view(vnode) { throw new Error('Component#view must be implemented by subclass'); @@ -60,6 +64,10 @@ export default class Component { return selector ? $element.find(selector) : $element; } + render() { + return m(this, this.props); + } + static component(props: ComponentProps | any = {}, children?: Mithril.Children) { const componentProps: ComponentProps = Object.assign({}, props);