title: DurandalJS and composing Child Views with Parameters
body: <p>I'm having some difficulty transitioning from Knockout's template binding to the Durandal compose binding.</p>
  
  <p>In my old project, I have a list of tabs which can be swapped into center stage by placing them into the "selectedTabSection" observable. The templateId was a property of the sub-view.  So in my parent view, I created instances of my child models like this:</p>
  
  <pre><code>self.tabSections([
                      new BasicTabViewModel(self, db),
                      new BiometricTabViewModel(self, db),
                      new ActivityTabViewModel(self, db),
                      new SurveyTabViewModel(self, db),
                      new CommunicationTabViewModel(self, db),
                      new ReferralTabViewModel(self, db),
                      new GoalTabViewModel(self, db),
                      new NcpTabViewModel(self, db),
                      new CriticalValuesViewModel(self, db),
                      new ConditionManagement(self, db)
                  ]);
  </code></pre>
  
  <p>Then when I wanted to show one, I'd place it into the active observable:</p>
  
  <pre><code>self.selectedTabSection(self.tabSections()[0]);
  </code></pre>
  
  <p>When I change to the compose binding, it seems that Durandal cannot find the associated Views for my ViewModels because I'm binding instances of the models rather than the constructor of the ViewModel itself. In other words, </p>
  
  <pre><code>self.selectedTabSection(BasicTabViewModel);
  </code></pre>
  
  <p>Finds the appropriate view, whereas </p>
  
  <pre><code>self.selectedTabSection(new BasicTabViewModel(self, db));
  </code></pre>
  
  <p>does not.</p>
  
  <p>How can I get the viewLocator to understand that I'm passing an instance rather than the ViewModel constructor itself? If I cannot, how do I pass parameters to my child views since they haven't been initialized until they are composed?</p>
  
  <p>EDIT/UPDATE:</p>
  
  <p>It looks like there's something to do with how I've composed my child ViewModels.  Durandal appears to have issue when you return an object from the ViewModel's constructor.  </p>
  
  <p>This seems to work as expected:</p>
  
  <pre><code>var viewModel = function (parentVm, db) {
      var self = this;
  } 
  </code></pre>
  
  <p>Whereas this:</p>
  
  <pre><code>var viewModel = function(parentVm, db){
       var self = this;
       //public api
       return {};
  }
  </code></pre>
  
  <p>Does not. Something about returning an object from the constructor make DurandalJS get lost when trying to locate the View and also makes a mess of various scopes. I'm considering re-writing my scripts to fit, but this pattern of returning a object from a constructor has served me well for many moons (prior to Durandal) Curious...</p>