title: Q solution for deferred ajax and when() done()
body: <p>Using Durandal SPA I have in my <em>shell.js</em> :</p>
  
  <pre><code>function activate() {
      datacontext.getUser(user);
      return datacontext
          .primeData()
          .then(boot)
          .fail(failedInitialization); //return for durandal 
  }
  </code></pre>
  
  <p>THe <strong>boot()</strong> function depends on the result from <strong>datacontext.getUser(user)</strong>.</p>
  
  <p>I would like to get the user credentials before activating. If <strong>primeData()</strong> doesn't do much (at the moment):</p>
  
  <pre><code>var primeData = function() {
          return Q.all([]);
                 };
  </code></pre>
  
  <p>then <strong>boot()</strong> doesn't get the result from the datacontext:</p>
  
  <pre><code>var getUser = function(userObservable) {
              userObservable();
              var options =
              {
                  url: 'api/user',
                  type: 'GET',
                  datatype: 'json'
              };
  
              return $.ajax(options).then(queryOk).fail(queryNotOk);
  
              function queryOk(data) {
                  userObservable(model.user(data));
              }
  
              function queryNotOk(data, textStatus) {
                 ...
              }
          };
  </code></pre>
  
  <p>The question is: How can I use Q instead of jQuery's <em>$.when().done()</em>:</p>
  
  <pre><code> $.when(datacontext.getUser(user)).done(function() {
              return datacontext
                  .primeData()
                  .then(boot)
                  .fail(failedInitialization);
          }); 
  </code></pre>