Introduce minimal VG-Core module registry
Dieser Commit ist enthalten in:
@@ -0,0 +1,48 @@
|
||||
(function () {
|
||||
const modules = new Map();
|
||||
|
||||
function validateModuleDefinition(moduleDefinition) {
|
||||
if (!moduleDefinition || typeof moduleDefinition !== "object") {
|
||||
throw new TypeError("moduleDefinition must be an object");
|
||||
}
|
||||
|
||||
if (
|
||||
typeof moduleDefinition.id !== "string" ||
|
||||
moduleDefinition.id.trim() === ""
|
||||
) {
|
||||
throw new TypeError("moduleDefinition.id is required");
|
||||
}
|
||||
|
||||
if (
|
||||
typeof moduleDefinition.name !== "string" ||
|
||||
moduleDefinition.name.trim() === ""
|
||||
) {
|
||||
throw new TypeError("moduleDefinition.name is required");
|
||||
}
|
||||
}
|
||||
|
||||
function cloneModuleDefinition(moduleDefinition) {
|
||||
return { ...moduleDefinition };
|
||||
}
|
||||
|
||||
globalThis.VGCoreModuleRegistry = {
|
||||
registerModule(moduleDefinition) {
|
||||
validateModuleDefinition(moduleDefinition);
|
||||
|
||||
const storedModuleDefinition = cloneModuleDefinition(moduleDefinition);
|
||||
modules.set(storedModuleDefinition.id, storedModuleDefinition);
|
||||
|
||||
return cloneModuleDefinition(storedModuleDefinition);
|
||||
},
|
||||
|
||||
getModules() {
|
||||
return Array.from(modules.values(), cloneModuleDefinition);
|
||||
},
|
||||
|
||||
getModuleById(moduleId) {
|
||||
return modules.has(moduleId)
|
||||
? cloneModuleDefinition(modules.get(moduleId))
|
||||
: null;
|
||||
},
|
||||
};
|
||||
})();
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren