27 lines
718 B
JavaScript
27 lines
718 B
JavaScript
|
const modules = {
|
||
|
_cache: {},
|
||
|
_registry: {},
|
||
|
require(moduleName) {
|
||
|
if (this._cache[moduleName]) {
|
||
|
return this._cache[moduleName];
|
||
|
}
|
||
|
|
||
|
if (this._registry[moduleName]) {
|
||
|
const loaderFunction = this._registry[moduleName];
|
||
|
this._cache[moduleName] = loaderFunction(1);
|
||
|
return this._cache[moduleName];
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
},
|
||
|
register(moduleName, loaderFunction) {
|
||
|
this._registry[moduleName] = loaderFunction;
|
||
|
this._cache[moduleName] = loaderFunction(0);
|
||
|
},
|
||
|
registerLazy(moduleName, loaderFunction) {
|
||
|
this._registry[moduleName] = loaderFunction;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
window.modules = modules;
|