Ox.load: allow for passing array of modules

This commit is contained in:
rolux 2012-06-17 15:56:13 +02:00
parent 8d8e087e3d
commit c9474ee04e

View file

@ -96,7 +96,7 @@ Ox.Break = function() {
Ox.BreakError = new SyntaxError('Illegal Ox.Break() statement'); Ox.BreakError = new SyntaxError('Illegal Ox.Break() statement');
/*@ /*@
Ox.load <f> Loads a module Ox.load <f> Loads one or more modules
A module named "Foo" provides `Ox.Foo/Ox.Foo.js`, in which it defines one A module named "Foo" provides `Ox.Foo/Ox.Foo.js`, in which it defines one
method, `Ox.load.Foo`, that takes two arguments, `options` and `callback`, method, `Ox.load.Foo`, that takes two arguments, `options` and `callback`,
and calls `callback` with one argument, `true` for success or `false` if an and calls `callback` with one argument, `true` for success or `false` if an
@ -106,20 +106,31 @@ Ox.load <f> Loads a module
(module, options, callback) -> <u> undefined (module, options, callback) -> <u> undefined
(modules, callback) -> <u> undefined (modules, callback) -> <u> undefined
module <s> Module name module <s> Module name
modules <o> Multiple modules {name: options, ...}
options <o> Module options options <o> Module options
modules <a|o> Multiple modules
Either `[moduleA, {moduleB: options}, ...]`
or `{moduleA: {}, moduleB: {options}, ...}`
callback <f> Callback function callback <f> Callback function
success <b> If true, the module has been loaded successfully success <b> If true, all modules have been loaded successfully
@*/ @*/
Ox.load = function() { Ox.load = function() {
var callback = arguments[arguments.length - 1], var callback = arguments[arguments.length - 1],
counter = 0, counter = 0, length, modules = {}, success = 0,
isObject = Ox.isObject(arguments[0]), type = Ox.typeOf(arguments[0]);
length, if (type == 'string') {
modules = isObject ? arguments[0] : {}, modules = Ox.extend(
success = 0; {}, arguments[0], Ox.isObject(arguments[1]) ? arguments[1] : {}
if (!isObject) { );
modules[arguments[0]] = Ox.isObject(arguments[1]) ? arguments[1] : {}; } else if (type == 'array') {
arguments[0].forEach(function(value) {
if (Ox.isString(value)) {
modules[value] = {};
} else {
Ox.extend(modules, value)
}
});
} else if (type == 'object') {
modules = arguments[0];
} }
length = Ox.len(modules); length = Ox.len(modules);
Ox.forEach(modules, function(options, module) { Ox.forEach(modules, function(options, module) {