mirror of
https://github.com/flarum/core.git
synced 2025-08-05 07:57:46 +02:00
common: add constructor & render method to Component
This commit is contained in:
@@ -11,7 +11,11 @@ export type ComponentProps = {
|
|||||||
export default class Component<T extends ComponentProps = any> {
|
export default class Component<T extends ComponentProps = any> {
|
||||||
element: HTMLElement;
|
element: HTMLElement;
|
||||||
|
|
||||||
props = <T>{};
|
props: T;
|
||||||
|
|
||||||
|
constructor(props: T = <T>{}) {
|
||||||
|
this.props = props;
|
||||||
|
}
|
||||||
|
|
||||||
view(vnode) {
|
view(vnode) {
|
||||||
throw new Error('Component#view must be implemented by subclass');
|
throw new Error('Component#view must be implemented by subclass');
|
||||||
@@ -60,6 +64,10 @@ export default class Component<T extends ComponentProps = any> {
|
|||||||
return selector ? $element.find(selector) : $element;
|
return selector ? $element.find(selector) : $element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return m(this, this.props);
|
||||||
|
}
|
||||||
|
|
||||||
static component(props: ComponentProps | any = {}, children?: Mithril.Children) {
|
static component(props: ComponentProps | any = {}, children?: Mithril.Children) {
|
||||||
const componentProps: ComponentProps = Object.assign({}, props);
|
const componentProps: ComponentProps = Object.assign({}, props);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user