Permalink
Browse files

Properly handle multiple ids in ensure

  • Loading branch information...
1 parent 8c16b19 commit 26917b13cca557fa76255419b7888421bee33219 @kriszyp committed Aug 17, 2010
Showing with 20 additions and 2 deletions.
  1. +20 −2 lib/nodules.js
View
@@ -259,9 +259,27 @@ function makeRequire(currentId){
uri = resolveUri(currentId, uri, getPackage(currentId).mappings);
return factories[uri];
}
- require.ensure = function(id, callback){
+ var ensure = require.ensure = function(id, callback){
+ var require = makeRequire(uri);
if(id instanceof Array){
- id.forEach();
+ waitingOn++;
+ try{
+ var results = id.map(ensure);
+ }finally{
+ waitingOn--;
+ }
+ if(waitingOn){
+ if(callback){
+ callbacks.unshift(callback);
+ }
+ }else{
+ if(callback){
+ var uri = resolveUri(currentId, id[0], getPackage(currentId).mappings),
+ require = makeRequire(uri);
+ callback(require);
+ }
+ }
+ return results;
}
var uri = resolveUri(currentId, id, getPackage(currentId).mappings),
require = makeRequire(uri),

0 comments on commit 26917b1

Please sign in to comment.