I am currently upgrade a jquery ui widget to use Js API 4.x. I was using Js API 3.x in my widget, since the 3.x support legacy code, i could call a module or class easily; for example, this.locationGraphic=new esri.Graphic(center, symbol, feature.attributes, infotemplate). The 4.x no longer support legacy code, l have to load those AMD module into the widget, which is not simple. I could pass those class or module parameters into my widget to avoid loading. But it is a long list. Is there any better ideas or simple ways to do it?(Any ideas are welcome:))
Heming,
l have to load those AMD module into the widget, which is not simple
What is not simple about that? Just like you have your requires in your main js code you just define the modules in your custom widget code.
var graphic=new esri.Graphic(....); now i have to pass the parameter like the following
require(["esri/Graphic",...], function(Grapic){
....
view.then(function () {
//load the portal tool kit
$('#tool').location_portal({
view: view,
movable: true,
Graphic: Graphic
});
});
........
});
Heming,
No there is not a simpler or better way that is the AMD module way of doing things. You were able to by pas this in the past because of Legacy coding style but now in 4.x Legacy is not supported so you are required to load all modules using AMD style coding.
I know 4.x is AMD only. So i am aware of that. Just don't want my jquery widget have too many dependencies, maybe i will bypass, using Jquery.trigger() to pass JSON object and let hosting page to deal with JSON uing API. Thanks for answering my question. It is indeed helpful.
You'll have fewer dependence this way, since you'll only be loading only the modules you need.
I imagine using the older style, you're loading everything, even if you're only using a small number of classes.
when working with 3.x, i don't need to load any modules, because the hosting page already include the API link, i only need to use legacy code when i created instance of a class. now, i have to pass module to my widget. that is what i mean. Thanks for response anyway.