|
315 | 315 | } |
316 | 316 |
|
317 | 317 | return { |
318 | | - getModuleConfig: function(name) { |
319 | | - if(!modules[name]) { |
| 318 | + /** |
| 319 | + * Let you get a module config object |
| 320 | + * @param moduleName String the name of the module |
| 321 | + * @returns {*} |
| 322 | + */ |
| 323 | + getModuleConfig: function(moduleName) { |
| 324 | + if(!angular.isString(moduleName)) { |
| 325 | + throw new Error('You need to give the name of the module to get'); |
| 326 | + } |
| 327 | + if(!modules[moduleName]) { |
320 | 328 | return null; |
321 | 329 | } |
322 | | - return modules[name]; |
| 330 | + return modules[moduleName]; |
323 | 331 | }, |
324 | 332 |
|
325 | | - setModuleConfig: function(module) { |
326 | | - modules[module.name] = module; |
327 | | - return module; |
| 333 | + /** |
| 334 | + * Let you define a module config object |
| 335 | + * @param moduleConfig Object the module config object |
| 336 | + * @returns {*} |
| 337 | + */ |
| 338 | + setModuleConfig: function(moduleConfig) { |
| 339 | + if(!angular.isObject(moduleConfig)) { |
| 340 | + throw new Error('You need to give the module config object to set'); |
| 341 | + } |
| 342 | + modules[moduleConfig.name] = moduleConfig; |
| 343 | + return moduleConfig; |
328 | 344 | }, |
329 | 345 |
|
| 346 | + /** |
| 347 | + * Returns the list of loaded modules |
| 348 | + * @returns {string[]} |
| 349 | + */ |
330 | 350 | getModules: function() { |
331 | 351 | return regModules; |
332 | 352 | }, |
333 | 353 |
|
334 | | - // deprecated |
335 | | - loadTemplateFile: function(paths, params) { |
336 | | - return filesLoader({files: paths}, params); |
| 354 | + /** |
| 355 | + * Let you check if a module has been loaded into Angular or not |
| 356 | + * @param modulesNames String/Object a module name, or a list of module names |
| 357 | + * @returns {boolean} |
| 358 | + */ |
| 359 | + isLoaded: function(modulesNames) { |
| 360 | + var moduleLoaded = function(module) { |
| 361 | + var isLoaded = regModules.indexOf(module) > -1; |
| 362 | + if(!isLoaded) { |
| 363 | + isLoaded = !!moduleExists(module); |
| 364 | + } |
| 365 | + return isLoaded; |
| 366 | + } |
| 367 | + if(angular.isString(modulesNames)) { |
| 368 | + modulesNames = [modulesNames]; |
| 369 | + } |
| 370 | + if(angular.isArray(modulesNames)) { |
| 371 | + var i, len; |
| 372 | + for(i = 0, len = modulesNames.length; i < len; i++) { |
| 373 | + if(!moduleLoaded(modulesNames[i])) { |
| 374 | + return false; |
| 375 | + } |
| 376 | + } |
| 377 | + return true; |
| 378 | + } else { |
| 379 | + throw new Error('You need to define the module(s) name(s)'); |
| 380 | + } |
337 | 381 | }, |
338 | 382 |
|
| 383 | + /** |
| 384 | + * Load a module or a list of modules into Angular |
| 385 | + * @param module Mixed the name of a predefined module config object, or a module config object, or an array of either |
| 386 | + * @param params Object optional parameters |
| 387 | + * @returns promise |
| 388 | + */ |
339 | 389 | load: function(module, params) { |
340 | 390 | var self = this, |
341 | 391 | config = null, |
|
0 commit comments