trilium/src/public/javascripts/widgets/component.js

24 lines
560 B
JavaScript
Raw Normal View History

2020-01-16 04:36:01 +08:00
export default class Component {
/** @param {AppContext} appContext */
constructor(appContext) {
this.appContext = appContext;
/** @type Component[] */
this.children = [];
}
eventReceived(name, data) {
const fun = this[name + 'Listener'];
if (typeof fun === 'function') {
fun.call(this, data);
}
for (const child of this.children) {
child.eventReceived(name, data);
}
}
trigger(name, data) {
this.appContext.trigger(name, data);
}
}