I'd like to use the Require.js Sugar Syntax for loading JSAPI modules, i.e.:
define(function (require) {
var map= require('esri/map'),
//do something with map
});
but when I try to instantiate a new Map object, an error is thrown that says "undefinedModule".
How can we make this work?
Message was edited by: Brian Behling
Dojo doesn't yet support this. Right now, it needs to be
define(function (require) {
require(['esri/map'], function(Map) {
//do something with map
});
});
This lazy loads the map. That being said, I did see some discussion at one point not long ago in Dojo IRC that this would be implemented, but I think it's going to be in Dojo2 as I don't see commit history for it in Dojo 1.x. As of right now, this only works if you have previously already loaded the module asynchronously somewhere else in your application.
That's disappointing. It would be nice to use the sugar syntax when you have to load many ESRI modules. It gets quite messy using the standard syntax.
Maybe in JSAPI 4.0, ESRI will just use require.js and drop the Dojo loaders?
There will be some stuff coming up soon that will allow expanded RequireJS support. Dojo is not going anywhere, but the ability to use RequireJS loader will be easier. RequireJS has some limitations when it comes to cross-domain loading of files that Dojo can handle.