mirror of https://github.com/status-im/metro.git
Allow already loaded modules to be `require`’d by name string in dev mode
Summary: The code to require modules by their name (rather than their numeric ID) was buggy, because it didn’t check whether the module factory was already executed and the module already existed. This diff checks the already loaded modules, too, when loading modules by name. Reviewed By: lexs Differential Revision: D3281350 fbshipit-source-id: cef236e152fe5484f21c877d6cee37433fa11c76
This commit is contained in:
parent
f9da45197f
commit
9dcdb156f0
|
@ -41,17 +41,19 @@ function define(moduleId, factory) {
|
|||
}
|
||||
|
||||
function require(moduleId) {
|
||||
const module = modules[moduleId];
|
||||
const module = __DEV__
|
||||
? modules[moduleId] || modules[verboseNamesToModuleIds[moduleId]]
|
||||
: modules[moduleId];
|
||||
return module && module.isInitialized
|
||||
? module.exports
|
||||
: guardedLoadModule(moduleId, module);
|
||||
}
|
||||
|
||||
var inGuard = false;
|
||||
let inGuard = false;
|
||||
function guardedLoadModule(moduleId, module) {
|
||||
if (!inGuard && global.ErrorUtils) {
|
||||
inGuard = true;
|
||||
var returnValue;
|
||||
let returnValue;
|
||||
try {
|
||||
returnValue = loadModuleImplementation(moduleId, module);
|
||||
} catch (e) {
|
||||
|
|
Loading…
Reference in New Issue