Just instanciate module one time
This commit is contained in:
@@ -179,21 +179,22 @@ function Modular (options) {
|
||||
}
|
||||
|
||||
function loadModule (mod) {
|
||||
if (mod.module === undefined) {
|
||||
if (mod.instance === undefined) {
|
||||
mod.module = require(mod.fullPath);
|
||||
|
||||
if (mod.module instanceof Function) {
|
||||
mod.instance = mod.module(get.bind(undefined,mod));
|
||||
}
|
||||
else if (mod.module.onLoad instanceof Function){
|
||||
mod.module.onLoad(get.bind(undefined, mod));
|
||||
mod.instance = mod.module;
|
||||
}
|
||||
else {
|
||||
mod.instance = mod.module;
|
||||
}
|
||||
}
|
||||
|
||||
if (mod.module instanceof Function) {
|
||||
let instanceModule = mod.module(get.bind(undefined,mod));
|
||||
return instanceModule ? instanceModule : mod.module;
|
||||
}
|
||||
else if (mod.module.onLoad instanceof Function){
|
||||
let instanceModule = mod.module.onLoad(get.bind(undefined, mod));
|
||||
return instanceModule ? instanceModule : mod.module;
|
||||
}
|
||||
else {
|
||||
return mod.module;
|
||||
}
|
||||
return mod.instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -269,6 +270,7 @@ function Modular (options) {
|
||||
}
|
||||
|
||||
opts.module = undefined;
|
||||
opts.instance = undefined;
|
||||
|
||||
//Clear the cache of the module if exists
|
||||
if (require.cache[opts.fullPath]) {
|
||||
|
||||
Reference in New Issue
Block a user