mirror of
https://github.com/zadam/trilium.git
synced 2025-11-05 12:55:55 +01:00
start of the refactoring to widget system
This commit is contained in:
41
src/public/javascripts/widgets/basic_widget.js
Normal file
41
src/public/javascripts/widgets/basic_widget.js
Normal 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;
|
||||
Reference in New Issue
Block a user