Skip to content

Instantly share code, notes, and snippets.

@dmachi
Created November 27, 2010 17:56
Show Gist options
  • Save dmachi/718119 to your computer and use it in GitHub Desktop.
Save dmachi/718119 to your computer and use it in GitHub Desktop.
wrapped dojo require to work around addOnLoad issue in xd when the module has already been loaded
// check to see if this loaded module already exists. Returns a deferred that will already be resolved or
// or will resolve with an addOnLoad after the require
var dynrequire = function(names){
var def = new dojo.Deferred();
var loading=false;
dojo.forEach(names, function(n){
if (!dojo._loadedModules[n]){
dojo.require(n);
loading=true;
}
});
if (!loading){
def.resolve(true);
}else{
dojo.addOnLoad(function(){
def.resolve(true);
});
}
return def.promise;
}
//then something like this:
dojo.when(dynrequire('foo.bar'), function(){
/* whatever */
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment