Ox.load: allow for passing array of modules
This commit is contained in:
parent
8d8e087e3d
commit
c9474ee04e
1 changed files with 23 additions and 12 deletions
|
@ -96,30 +96,41 @@ 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
|
||||||
error occurred. Generally, the module should define `Ox.Foo` and attach its
|
error occurred. Generally, the module should define `Ox.Foo` and attach its
|
||||||
own methods there.
|
own methods there.
|
||||||
(module, callback) -> <u> undefined
|
(module, callback) -> <u> undefined
|
||||||
(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) {
|
||||||
|
|
Loading…
Reference in a new issue