mirror of
https://github.com/flarum/framework.git
synced 2025-05-24 23:59:57 +08:00
Replace Ember app with Mithril app
This commit is contained in:
42
js/lib/component.js
Normal file
42
js/lib/component.js
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
|
||||
*/
|
||||
export default class Component {
|
||||
/**
|
||||
|
||||
*/
|
||||
constructor(props) {
|
||||
this.props = props || {};
|
||||
|
||||
this.element = m.prop();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
$(selector) {
|
||||
return selector ? $(this.element()).find(selector) : $(this.element());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
static component(props) {
|
||||
props = props || {};
|
||||
var view = function(component) {
|
||||
component.props = props;
|
||||
return component.view();
|
||||
};
|
||||
view.$original = this.prototype.view;
|
||||
var output = {
|
||||
props: props,
|
||||
component: this,
|
||||
controller: this.bind(undefined, props),
|
||||
view: view
|
||||
};
|
||||
if (props.key) {
|
||||
output.attrs = {key: props.key};
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user