title: MVVM with Knockout.js
body: <p>I'm trying to implement a MVVM based Single Page Application and currently am using the framework Knockout.js to handle the viewmodel/view portion of MVVM. I'm confused though, as every example I've looked at for implementing Knockout involves saving an entire viewmodel to the database. Aren't these examples missing a "model" step, where the viewmodel syncs with the data-layer model and the model does validation / Server synchronization.</p>
  
  <p>I would like to have multiple different templates/views on the single page each with a different viewmodel. Another thing that I find is missing with knockout.js is synchronizing a single model (not viewmodel) across different views. I don't think it makes sense to have one giant viewmodel that every view shares, so I was thinking that each view would have its own viewmodel but each viewmodel would sync with the fields of just a few application-wide models that are needed for each view.</p>
  
  <p>The page I'm working on fetches a giant model (30+ fields, multiple layers of parent/child relationships) and I think it makes sense to just have all of my viewmodels sync with this model. I have investigated Knockback.js (which combines knockout.js and backbone.js) however I ended up re-writing the majority of the functions such as fetch, set, save, because the page is getting data from an API (and I can't just sync an entire model back and forth with the server) so I decided against it.
  <br /><br /><em>visual example of my application:</em></p>
  
  <p>(model layer)
  M | M</p>
  
  <p>(viewmodel/view layer) VM-V | VM-V | VM-V | VM-V</p>
  
  <p><br /><em>another example</em></p>
  
  <p>An example model would be User = {firstName: "first", lastName: "last", ... }
  <br /><br />one viewmodel only needs first name, another viewmodel only needs last name
  <br />ViewModelA={firstName: app.User.firstName()}<br />ViewModelB={firstName: app.User.lastName()}<br />
  <br /></p>
  
  <p>Is the only way to do this to define a pub/sub system for Model and Viewmodel changes? Is this even good/maintainable architecture? Am I missing a basic concept here? All advice welcome.</p>