title: Am I structuring my app the right way? - Backbone.js
body: <p>I am very new to Javascript and backbone.js. Have developed an application in AS3 using RobotLegs and need to port it to Javascipt. For the client side MVC, I started looking at Backbone.js. The concepts seem straightforward but I'm a little unsure about doing things the "right" way. Also have some places I'm stuck...</p>
  
  <p>So basically, I have this web service (non RESTful) that I need to GET a JSON object with the apps config from. Ideally, I think the best way to make this call would be from a Backbone model, but I'm not sure how to override the URL and Parse method to make it work with Non Restful services. So for now I'm making an Ajax call to it from outside of the Model in App.js (code shared below).</p>
  
  <p>Once I get the data from the JSON call, I want to store it in a ConfigModel (SingleTon Model) object that I can query from modules to retrieve value objects that eventually populate some views. I have 2 issues here.</p>
  
  <p>1) I don't know how to implement a Singleton Model using Backbone.js
  2) I don't know how I can divide my ConfigModel further into smaller models/collections and if I need to make them Singleton too or just pass them to the View constructors.</p>
  
  <p>I'm using Require.js to define([]) the dependent modules for a particular view/model etc. Now I'm not sure about the scope of the loaded modules. If I need to make them Singleton then I should just load them once somewhere and then inject a dependency into other classes/module objects. How do I carry this out with Backbone.js ???</p>
  
  <p>Lastly, I want to use custom events throughout the framework.. Sort of Framework events that I can dispatch globally and listen to from Models/Views etc... </p>
  
  <p>As you can see, I'm pretty confused regarding scopes/singletons and how all of this fits in with Backbone.js &amp; Require. </p>
  
  <p>Here's how I have my app structured as of now...</p>
  
  <p>1) My index.html file loads up "Main.js" with Require.js </p>
  
  <p>2) In Main.js I load up App.js and call init on it. Init calls a getConfig() function which makes an AJAX call to the web service and gets and parses a JSON text file. This I wanted to store in the singleton ConfigModel. However, I have that commented right now because I started playing around with ways to make the webservice call from with my ConfigModel itself... Which Didn't work.</p>
  
  <p>3) Then I have a router with a default URL map. I initialize the Router after succesfully receiving the JSON from the web service. I'm not sure if this is correct or I should make the Ajax call from the Router?</p>
  
  <p>Here's the code : <a href="http://pastebin.com/HHRF88Tq" rel="nofollow">http://pastebin.com/HHRF88Tq</a></p>
  
  <p>I know I'm all over the place, but if someone could guide me in the right direction, I'd really appreciate it....</p>
  
  <p>Thanks a bunch.</p>
  
  <p>Sameer</p>