2015-04-25 22:28:39 +09:30
|
|
|
/**
|
|
|
|
|
|
|
|
*/
|
|
|
|
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 || {};
|
2015-05-02 08:45:11 +09:30
|
|
|
if (this.props) {
|
2015-05-18 15:27:39 +09:30
|
|
|
this.props(props);
|
2015-05-02 08:45:11 +09:30
|
|
|
}
|
2015-04-25 22:28:39 +09:30
|
|
|
var view = function(component) {
|
|
|
|
component.props = props;
|
2015-05-14 22:23:25 +09:30
|
|
|
var vdom = component.view();
|
|
|
|
vdom.attrs = vdom.attrs || {};
|
2015-06-24 17:56:39 +09:30
|
|
|
var oldConfig = vdom.attrs.config;
|
|
|
|
vdom.attrs.config = function() {
|
|
|
|
var args = [].slice.apply(arguments);
|
|
|
|
component.element(args[0]);
|
|
|
|
if (oldConfig) {
|
|
|
|
oldConfig.apply(component, args);
|
2015-05-14 22:23:25 +09:30
|
|
|
}
|
|
|
|
}
|
|
|
|
return vdom;
|
2015-04-25 22:28:39 +09:30
|
|
|
};
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|