Automatically hook up onload/config functions

So that every component's DOM can be config'd by extensions
This commit is contained in:
Toby Zerner 2015-05-14 22:23:25 +09:30
parent f2c07218b0
commit d85ae8745e

View File

@ -18,6 +18,14 @@ export default class Component {
return selector ? $(this.element()).find(selector) : $(this.element());
}
onload(element) {
this.element(element);
}
config() {
}
/**
*/
@ -28,7 +36,18 @@ export default class Component {
}
var view = function(component) {
component.props = props;
return component.view();
var vdom = component.view();
vdom.attrs = vdom.attrs || {};
if (!vdom.attrs.config) {
vdom.attrs.config = function() {
var args = [].slice.apply(arguments);
if (!args[1]) {
component.onload.apply(component, args);
}
component.config.apply(component, args);
}
}
return vdom;
};
view.$original = this.prototype.view;
var output = {