Created
July 13, 2012 11:35
-
-
Save dmaevac/3104445 to your computer and use it in GitHub Desktop.
Require.js plugin to load multiple modules as a single object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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