Created
June 12, 2012 14:25
-
-
Save jonnyreeves/2917860 to your computer and use it in GitHub Desktop.
RequireJS Loading order
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
// This doesn't appear to be the case... | |
define(function (require) { | |
// Is there any guarantee that `moduleA` is loaded first? | |
var loadMeFirst = require('moduleA'); | |
var loadMeSecond = require('moduleB'); | |
}); |
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
// In this case `moduleA` *appears* to always be loaded before `moduleB` | |
define([ 'moduleA', 'moduleB' ], function (loadMeFirst, loadMeSecond) { | |
}); |
If you are using requirejs 2.0, the shim config is helpful for this kind of situation where you have implicit dependencies (the library does not call define()) but want to use it as a module:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for clarifying that, James. I ended up with this approach which seems to do the job - could you confirm it's the 'correct' way to handle ordered dependencies?