Compare commits

3 Commits

Author SHA1 Message Date
cc18f864ed Modular act as require if module isn't known 2015-08-20 22:48:20 +02:00
4694aaadd1 Just instanciate module one time 2015-08-03 21:56:26 +02:00
a838734f29 Typo 2015-08-02 22:36:06 +02:00

View File

@@ -150,8 +150,11 @@ function Modular (options) {
else if (modules.has(name)) {
mod = modules.get(name);
}
else {
return require(name);
}
//If the module as been found
//If the module has been found
if (mod) {
if (caller) {
if (mod.childrenOf === undefined) {
@@ -179,23 +182,24 @@ function Modular (options) {
}
function loadModule (mod) {
if (mod.module === undefined) {
if (mod.instance === undefined) {
mod.module = require(mod.fullPath);
}
if (mod.module instanceof Function) {
let instanceModule = mod.module(get.bind(undefined,mod));
return instanceModule ? instanceModule : mod.module;
mod.instance = mod.module(get.bind(undefined,mod));
}
else if (mod.module.onLoad instanceof Function){
let instanceModule = mod.module.onLoad(get.bind(undefined, mod));
return instanceModule ? instanceModule : mod.module;
mod.module.onLoad(get.bind(undefined, mod));
mod.instance = mod.module;
}
else {
return mod.module;
mod.instance = mod.module;
}
}
return mod.instance;
}
//Register a new module
//file : path of the module
@@ -269,6 +273,7 @@ function Modular (options) {
}
opts.module = undefined;
opts.instance = undefined;
//Clear the cache of the module if exists
if (require.cache[opts.fullPath]) {