调整了整个框架,模块化解耦
This commit is contained in:
36
js/core/module-registry.js
Normal file
36
js/core/module-registry.js
Normal file
@@ -0,0 +1,36 @@
|
||||
(function (global) {
|
||||
'use strict';
|
||||
|
||||
class ModuleRegistry {
|
||||
constructor() {
|
||||
this.modules = new Map();
|
||||
this.order = [];
|
||||
}
|
||||
|
||||
register(manifest) {
|
||||
if (!manifest || !manifest.id) {
|
||||
throw new Error('注册模块失败:缺少 id');
|
||||
}
|
||||
if (this.modules.has(manifest.id)) {
|
||||
console.warn(`模块 ${manifest.id} 已存在,将被覆盖`);
|
||||
} else {
|
||||
this.order.push(manifest.id);
|
||||
}
|
||||
this.modules.set(manifest.id, manifest);
|
||||
}
|
||||
|
||||
get(moduleId) {
|
||||
return this.modules.get(moduleId) || null;
|
||||
}
|
||||
|
||||
list() {
|
||||
return this.order.map((id) => this.modules.get(id));
|
||||
}
|
||||
|
||||
has(moduleId) {
|
||||
return this.modules.has(moduleId);
|
||||
}
|
||||
}
|
||||
|
||||
global.ModuleRegistry = new ModuleRegistry();
|
||||
})(window);
|
||||
Reference in New Issue
Block a user