You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
4 years ago
|
export default class VuES6Loader {
|
||
|
constructor(component_list) {
|
||
|
this.components = component_list
|
||
|
}
|
||
|
|
||
|
load() {
|
||
|
for ( const ComponentClass of Object.values(this.components) ) {
|
||
|
const method_properties = Object.getOwnPropertyNames(ComponentClass.prototype)
|
||
|
|
||
|
const watch = {}
|
||
|
method_properties.filter(x => x.startsWith('watch_')).some(method_name => {
|
||
|
const field_name = method_name.substr(6)
|
||
|
const handler = function(...args) {
|
||
|
return ComponentClass.prototype[method_name].bind(this)(...args)
|
||
|
}
|
||
|
watch[field_name] = handler
|
||
|
})
|
||
|
|
||
|
const methods = {}
|
||
|
method_properties.filter(x => !x.startsWith('watch_')).some(method_name => {
|
||
|
const handler = function(...args) {
|
||
|
return ComponentClass.prototype[method_name].bind(this)(...args)
|
||
|
}
|
||
|
methods[method_name] = handler
|
||
|
})
|
||
|
|
||
|
Vue.component(ComponentClass.selector, {
|
||
|
props: ComponentClass.props,
|
||
|
data: () => {
|
||
|
return new ComponentClass()
|
||
|
},
|
||
|
watch,
|
||
|
methods,
|
||
|
template: ComponentClass.template,
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export class Component {
|
||
|
static get selector() { return '' }
|
||
|
static get template() { return '' }
|
||
|
static get props() { return [] }
|
||
|
}
|
||
|
|