feat(core) auto register on... options as event listener callbacks

This commit is contained in:
Benjamin Wegener
2023-11-19 17:15:17 +00:00
parent 0e44dc4599
commit e56162ff9e

View File

@@ -21,6 +21,27 @@ class Cetra extends Emitter {
constructor(options = new Map()) { constructor(options = new Map()) {
super(); super();
this.#identifier = this.uid(); this.#identifier = this.uid();
if (!(options instanceof Map) && typeof options == 'object') {
options = new Map(Object.entries(options));
}
for (const key of Cetra.#defaultSettings.keys()) {
let value = options.get(key);
if (typeof value == 'undefined') {
value = Cetra.#defaultSettings.get(key);
}
this.#internals
.get('settings')
.set(key, value);
}
for (const [key, cb] of options) {
if (!key.startsWith('on') || typeof cb != 'function') continue;
this.on(key, cb);
}
this.#init(); this.#init();
} }
@@ -61,7 +82,7 @@ class Cetra extends Emitter {
); );
Cetra.#instances.set(this.#identifier, this); Cetra.#instances.set(this.#identifier, this);
this.emit('afterInit', this); this.emit('onAfterInit', this);
} }
/** /**