Created
November 27, 2010 17:56
-
-
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
This file contains hidden or 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
// 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