refactor: module reference

This commit is contained in:
cha0s 2021-03-31 10:33:45 -05:00
parent 7ae927d78a
commit 42a40934fa

View File

@ -21,10 +21,12 @@ export default class Latus {
this.config = config; this.config = config;
this.originalConfig = JSON.parse(JSON.stringify(this.config)); this.originalConfig = JSON.parse(JSON.stringify(this.config));
this.hooks = {}; this.hooks = {};
this.modules = {};
const entries = Object.entries(modules); const entries = Object.entries(modules);
debug('latus paths: %O', entries.map(([plugin]) => plugin)); debug('latus paths: %O', entries.map(([plugin]) => plugin));
for (let i = 0; i < entries.length; i++) { for (let i = 0; i < entries.length; i++) {
const [plugin, M] = entries[i]; const [plugin, M] = entries[i];
this.modules[plugin] = M;
if (M.default) { if (M.default) {
const {default: {hooks}} = M; const {default: {hooks}} = M;
if (hooks) { if (hooks) {
@ -275,6 +277,10 @@ export default class Latus {
}); });
} }
module(path) {
return this.modules[path];
}
refresh(plugin, M) { refresh(plugin, M) {
const keys = Object.keys(this.hooks); const keys = Object.keys(this.hooks);
for (let j = 0; j < keys.length; j++) { for (let j = 0; j < keys.length; j++) {
@ -286,6 +292,7 @@ export default class Latus {
} }
} }
} }
this.modules[plugin] = M;
if (M.default) { if (M.default) {
const {default: {hooks}} = M; const {default: {hooks}} = M;
if (hooks) { if (hooks) {