mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-08 01:05:28 +08:00
41 lines
790 B
JavaScript
41 lines
790 B
JavaScript
![]() |
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;
|