common: rework Component#render again to simplify substite m(class, props)

Can be used instead of m(DiscussionList, app.cache.discussionList.props), for example - it's now app.cache.discussionList.render()
This commit is contained in:
David Sevilla Martin 2020-03-18 16:50:48 -04:00
parent 5bc6e52190
commit 66b839d241
No known key found for this signature in database
GPG Key ID: F764F1417E16B15F
4 changed files with 5 additions and 15 deletions

View File

@ -65,18 +65,7 @@ export default class Component<T extends ComponentProps = any> implements ClassC
}
render() {
return m.fragment(
{
...this.props,
oninit: (...args) => this.oninit(...args),
oncreate: (...args) => this.oncreate(...args),
onbeforeupdate: (...args) => this.onbeforeupdate(...args),
onupdate: (...args) => this.onupdate.bind(...args),
onbeforeremove: (...args) => this.onbeforeremove.bind(...args),
onremove: (...args) => this.onremove.bind(...args),
},
this.view()
);
return m(this.constructor, this.props);
}
static component(props: ComponentProps | any = {}, children?: Mithril.Children) {

View File

@ -20,7 +20,7 @@ export default class CommentPost extends Post {
*/
revealContent: boolean = false;
postUser: Vnode<{}, PostUser>;
postUser!: Vnode<{}, PostUser>;
oninit(vnode) {
super.oninit(vnode);

View File

@ -76,7 +76,7 @@ export default class IndexPage extends Page {
view() {
if (!app.cache.discussionList) return;
const discussionList = m(DiscussionList, app.cache.discussionList.props);
const discussionList = app.cache.discussionList.render();
return (
<div className="IndexPage">

View File

@ -15,7 +15,7 @@ export type NotificationItem = {
name: string;
/**
* The icon to display in the column header/notificatio grid row.
* The icon to display in the column header/notification grid row.
*/
icon: string;
@ -60,6 +60,7 @@ export default class NotificationGrid extends Component<NotificationGridProps> {
state: !!preference,
disabled: typeof preference === 'undefined',
onchange: () => this.toggle([key]),
oninit: vnode => (this.inputs[key] = vnode.state),
});
})
);