My struggle to migrate to AMD style

Discussion created by evtguy on Apr 28, 2015
Latest reply on May 1, 2015 by evtguy

I don’t know how effective this post will be but I’m having a real hard time understanding how to migrate my projects previously written using the legacy style Dojo over to the AMD framework. First, let me state that I DO understand the structure of ESRI’s AMD styled samples where the JS code is either all in the HTML file or as a single, standalone JS file. I’ve seen and read this ESRI blog post. My comprehension goes away when I look at my own projects where I have developed my code across multiple JS files.


I’m attaching a PDF that is typical of how one of my legacy projects is structured. I want to focus the discussion at a higher level so the nitty gritty code is included.  Anyways, I have one JS file (initMap.JS) that contains the initialization function along with all the various dojo.require() statements. I might also have another JS file that contains pure JS functions (shown here as jsFunctions.JS) that do things such as read or write browser cookies, test for functionality, format dates, etc.


Lastly, I’ll also have one or several additional JS files which focus on a specific topic or functionality. In my example here, mapFunctions.JS contains a function which zooms the map to a selected feature and two functions which format the content for a layer’s infoWindow. The reportFunctions.JS file generates an HTML report in a new browser window and contains four functions which basically run sequentially (execute->buffer->query->process results).


I feel that it’s pretty straightforward to convert initMap.JS to an AMD style JS file. But what about mapFunctions.JS and the other JS files? I’m assuming that I need to convert these into “modules” but I don’t understand some aspects such as how I set up a file like my reportFunctions.JS which contains functions that call each other within the JS file. And where do external JS libraries such as JQuery fit into all of this? Do I need to do anything AMD related or just add a link in the HTML header as before?


I bought the book on ArcGIS Web Development by Rene Rubalcava and I feel that it does help me slightly but not all the way (probably because his coding style is different than the way my JS has developed). I kinda understand Rene’s technique of going from RUN.JS to MAIN.JS (pgs 80-84) but not much thereafter. To borrow a phrase from Apple, maybe I’m “not doing it right.”


I might not be too far from that “a-ha!” moment but I’m currently stymied.