start of the refactoring to widget system

This commit is contained in:
zadam
2020-01-11 21:19:56 +01:00
parent 51c3f98dde
commit 9e031dcd60
13 changed files with 437 additions and 276 deletions

View File

@@ -0,0 +1,41 @@
class BasicWidget {
/**
* @param {AppContext} appContext
*/
constructor(appContext) {
this.appContext = appContext;
this.widgetId = `widget-${this.constructor.name}`;
}
render() {
const $widget = $('<div>').attr('id', this.widgetId);
// actual rendering is async
this.doRender($widget);
return $widget;
}
/**
* for overriding
*
* @param {JQuery} $widget
*/
async doRender($widget) {}
eventReceived(name, data) {
const fun = this[name + 'Listener'];
if (typeof fun === 'function') {
fun.call(this, data);
}
}
trigger(name, data) {
this.appContext.trigger(name, data);
}
cleanup() {}
}
export default BasicWidget;