mirror of
https://github.com/flarum/framework.git
synced 2025-03-15 00:05:12 +08:00
common: add constructor & render method to Component
This commit is contained in:
parent
220a36c2e4
commit
66745916b3
@ -11,7 +11,11 @@ export type ComponentProps = {
|
||||
export default class Component<T extends ComponentProps = any> {
|
||||
element: HTMLElement;
|
||||
|
||||
props = <T>{};
|
||||
props: T;
|
||||
|
||||
constructor(props: T = <T>{}) {
|
||||
this.props = props;
|
||||
}
|
||||
|
||||
view(vnode) {
|
||||
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;
|
||||
}
|
||||
|
||||
render() {
|
||||
return m(this, this.props);
|
||||
}
|
||||
|
||||
static component(props: ComponentProps | any = {}, children?: Mithril.Children) {
|
||||
const componentProps: ComponentProps = Object.assign({}, props);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user