@adjust/core
Version:
A framework for creating highly customisable open source software
71 lines • 2.2 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const registry_1 = require("../registry/registry");
const programState_1 = require("../state/programState");
const separator = ":";
/**
* A class that can be used to reference a module.
* Can be used within an app to show a module's view without having a connection to that module.
*/
class ModuleReference {
constructor(modulePath, id) {
if (id !== undefined && typeof modulePath == "string") {
// Set the path and id directly
this.modulePath = modulePath;
this.id = id;
}
else {
// Get the path and id if the passed data is an already existing module id
const parts = modulePath.toString().split(separator);
this.modulePath = parts[0];
this.id = Number(parts[1]);
}
}
/**
* Retrieves the path to the class of the module
* @returns The path
*/
getModulePath() {
return this.modulePath;
}
/**
* Retrieves the ID of the module
* @returns the ID
*/
getID() {
return this.id;
}
/**@override */
toString() {
return this.modulePath + separator + this.id;
}
}
exports.ModuleReference = ModuleReference;
/**
* The class used internally to identify modules,
* provides some utility methods to obtain data from this identifier
*/
class ModuleID extends ModuleReference {
/**
* Retrieves the class of the module type this ID represents
* @returns The module class
*/
getModuleClass() {
return registry_1.Registry.getModuleClass(this.modulePath);
}
/**
* Retrieves the request path that corresponds to this module ID
* @returns The request path
*/
getRequestPath() {
return this.getModule().getRequestPath();
}
/**
* Retrieves the module that this ID uniquely identifies
* @returns The module that this ID identifies
*/
getModule() {
return programState_1.ProgramState.getModule(this);
}
}
exports.ModuleID = ModuleID;
//# sourceMappingURL=moduleID.js.map