title: JavaScript data access design
body: <p>I'm writing a single page app and have made it to writing the data access layer for the client-side. My question involves the proper design of it. While I do understand JS is callback-centric, I have to wonder if there's not a better way to do data-retrieval. Here is an example of how my current data access calls are formatted with callbacks:</p>
  
  <pre><code>$interface.getDashboard = function (callback) {
      callback({MyApplications:[]});
  };
  </code></pre>
  
  <p>Here is what I'm thinking of moving towards to eliminate the need for callbacks all over the place:</p>
  
  <pre><code>$interface.getApplications = function () {
      var v = amplify.store("api.applications");
      if (!v) {
          v = [];
          _get("/api/applications", null, function (results) {
              amplify.store("api.applications", results, { expires: _cacheTimeOut });
              dataRefresh();
          });
      }
  
      return v;
  };
  </code></pre>
  
  <p>In the code above, <code>dataRefresh()</code> will tell all applicable subscribers to refresh their data. So I guess you can say it's still using callbacks but in a different manner. </p>
  
  <p><strong>Is there a better way to do this? I've never written a strong data access layer for javascript before and would like to know if there's a pattern to follow as convention or a heuristic solution perhaps?</strong></p>