AnsweredAssumed Answered

code structure correctness

Question asked by nicolaraluca on May 26, 2014
Latest reply on May 28, 2014 by JGravois-esristaff

I have 2 questions related to the structure of my code:

1. I define a map and a dynamic layer and then I add a function that will be executed when both the layer and the map are loaded. In the beginning I added an event listener to the map that adds an event listener to the layer that executes the function. Is that correct? My problem is that the function initializeThings sometimes gets executed, sometimes doesn't. I haven't figured out a pattern for when it does and when not, but I assume it has something to do with these event listeners. In the end I set the event listener just on the layer, but still sometimes the function doesn't get executed.

2. Is it correct to "unnest" my functions from this main function(Map, DynamicLayer )? At the moment all my functions are inside this main function and I am not sure if that is the best practice.

require (["esri/map", "esri/layers/ArcGISTiledMapServiceLayer", "dojo/domReady!"],     function (Map, DynamicLayer ) {      var map = new Map("mapCanvas", options);        var layer = new DynamicLayer("http://....");    function initializeThings() {     }      //map.on("load", function (){layer.on("load", function() {initializeThings();} )} );   layer.on("load", function() {inititializeThings();} ); })