Just instanciate module one time

This commit is contained in:
2015-08-03 21:56:26 +02:00
parent a838734f29
commit 4694aaadd1

View File

@@ -179,23 +179,24 @@ function Modular (options) {
} }
function loadModule (mod) { function loadModule (mod) {
if (mod.module === undefined) { if (mod.instance === undefined) {
mod.module = require(mod.fullPath); mod.module = require(mod.fullPath);
}
if (mod.module instanceof Function) { if (mod.module instanceof Function) {
let instanceModule = mod.module(get.bind(undefined,mod)); mod.instance = mod.module(get.bind(undefined,mod));
return instanceModule ? instanceModule : mod.module;
} }
else if (mod.module.onLoad instanceof Function){ else if (mod.module.onLoad instanceof Function){
let instanceModule = mod.module.onLoad(get.bind(undefined, mod)); mod.module.onLoad(get.bind(undefined, mod));
return instanceModule ? instanceModule : mod.module; mod.instance = mod.module;
} }
else { else {
return mod.module; mod.instance = mod.module;
} }
} }
return mod.instance;
}
//Register a new module //Register a new module
//file : path of the module //file : path of the module
@@ -269,6 +270,7 @@ function Modular (options) {
} }
opts.module = undefined; opts.module = undefined;
opts.instance = undefined;
//Clear the cache of the module if exists //Clear the cache of the module if exists
if (require.cache[opts.fullPath]) { if (require.cache[opts.fullPath]) {