feat(core) auto register on... options as event listener callbacks
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user