From 66745916b3b252f61406b9e896e2db94405ac644 Mon Sep 17 00:00:00 2001 From: David Sevilla Martin Date: Fri, 31 Jan 2020 18:28:54 -0500 Subject: [PATCH] common: add constructor & render method to Component --- js/src/common/Component.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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);