Skip to content

Instantly share code, notes, and snippets.

@DveMac
Created July 13, 2012 11:35
Show Gist options
  • Save DveMac/3104445 to your computer and use it in GitHub Desktop.
Save DveMac/3104445 to your computer and use it in GitHub Desktop.
Require.js plugin to load multiple modules as a single object
define({
load: function (name, req, load, config) {
var n, k, names = name.split(','),
len = names.length,
loaded = {},
count = 0;
function subload(n, key) {
req([n], function (val) {
loaded[key] = val;
count += 1;
if (count === len) {
load(loaded);
}
});
}
while ((n = names.pop())) {
n = n.split(':');
k = n[1] || n[0].split(/[\/\\]/).pop();
subload(n[0], k);
}
}
});
define([
'hash!modules/one:modone,' +
'modules/two:modtwo,' +
'modules/three:modthree'
], function (modules) {
var m = new modules['one']();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment