appContext is now component

This commit is contained in:
zadam
2020-02-16 19:21:17 +01:00
parent 22c042e21f
commit e000fb4579
23 changed files with 70 additions and 103 deletions

View File

@@ -1,6 +1,5 @@
import utils from '../services/utils.js';
import Mutex from "../services/mutex.js";
import appContext from "../services/app_context.js";
export default class Component {
/**
@@ -16,7 +15,7 @@ export default class Component {
this.mutex = new Mutex();
}
async eventReceived(name, data) {
async handleEvent(name, data) {
await this.initialized;
const fun = this[name + 'Listener'];
@@ -31,18 +30,18 @@ export default class Component {
console.log(`Event ${name} in component ${this.componentId} took ${end-start}ms`);
}
await this.triggerChildren(name, data);
await this.handleEventInChildren(name, data);
}
async trigger(name, data) {
await appContext.trigger(name, data);
async triggerEvent(name, data) {
await this.parent.triggerEvent(name, data);
}
async triggerChildren(name, data) {
async handleEventInChildren(name, data) {
const promises = [];
for (const child of this.children) {
promises.push(child.eventReceived(name, data));
promises.push(child.handleEvent(name, data));
}
await Promise.all(promises);