1
0
mirror of https://github.com/flarum/core.git synced 2025-07-12 04:16:24 +02:00

Refactor component API a bit

This commit is contained in:
Toby Zerner
2015-06-26 19:09:43 +09:30
parent 4dbe87da77
commit e18d8b35e5
9 changed files with 33 additions and 32 deletions

View File

@ -22,6 +22,22 @@ export default class Component {
//
}
render() {
var vdom = this.view();
vdom.attrs = vdom.attrs || {};
if (!vdom.attrs.config) {
var component = this;
vdom.attrs.config = function() {
var args = [].slice.apply(arguments);
component.element(args[0]);
component.config.apply(component, args);
};
}
return vdom;
}
/**
*/
@ -32,18 +48,7 @@ export default class Component {
}
var view = function(component) {
component.props = props;
var vdom = component.view();
vdom.attrs = vdom.attrs || {};
if (!vdom.attrs.config) {
vdom.attrs.config = function() {
var args = [].slice.apply(arguments);
component.element(args[0]);
component.config.apply(component, args);
};
}
return vdom;
return component.render();
};
view.$original = this.prototype.view;
var output = {

View File

@ -2,7 +2,7 @@ import Component from 'flarum/component';
export default class Modal extends Component {
view() {
return m('div.modal.fade', {config: this.onload.bind(this)}, this.component && this.component.view())
return m('div.modal.fade', {config: this.onload.bind(this)}, this.component && this.component.render())
}
onload(element, isInitialized) {