simplification of sync event API

This commit is contained in:
zadam
2020-02-12 20:31:31 +01:00
parent 81a54cd4a0
commit 25553c9e67
5 changed files with 23 additions and 29 deletions

View File

@@ -55,19 +55,23 @@ class AppContext {
this.trigger('initialRenderComplete');
}
trigger(name, data, sync = false) {
async trigger(name, data) {
this.eventReceived(name, data);
const promises = [];
for (const component of this.components) {
component.eventReceived(name, data, sync);
promises.push(component.eventReceived(name, data));
}
await Promise.all(promises);
}
async eventReceived(name, data, sync) {
async eventReceived(name, data) {
const fun = this[name + 'Listener'];
if (typeof fun === 'function') {
await fun.call(this, data, sync);
await fun.call(this, data);
}
}