refactored keyboard actions into commands

This commit is contained in:
zadam
2020-02-16 19:54:11 +01:00
parent 880f4ad711
commit a679fedb58
14 changed files with 125 additions and 127 deletions

View File

@@ -18,7 +18,7 @@ export default class Component {
async handleEvent(name, data) {
await this.initialized;
const fun = this[name + 'Listener'];
const fun = this[name + 'Event'];
const start = Date.now();
@@ -48,15 +48,19 @@ export default class Component {
}
async triggerCommand(name, data = {}) {
const fun = this[name + 'Command'];
const called = await this.callMethod(fun, data);
const called = await this.handleCommand(name, data);
if (!called) {
await this.parent.triggerCommand(name, data);
}
}
async handleCommand(name, data) {
const fun = this[name + 'Command'];
return await this.callMethod(fun, data);
}
async callMethod(fun, data) {
if (typeof fun !== 'function') {
return false;