Notes/src/public/javascripts/widgets/basic_widget.js

39 lines
731 B
JavaScript
Raw Normal View History

class BasicWidget {
/**
* @param {AppContext} appContext
*/
constructor(appContext) {
this.appContext = appContext;
this.widgetId = `widget-${this.constructor.name}`;
}
render() {
// actual rendering is async
2020-01-12 20:15:05 +01:00
const $widget = this.doRender();
// $widget.attr('id', this.widgetId);
return $widget;
}
/**
* for overriding
*/
2020-01-12 20:15:05 +01:00
doRender() {}
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;