title: Creating new upshot js entities
body: <p>I'm building a site as a Single Page Application using ASP.NET MVC 4 Beta .</p>
  
  <p>The sample app talks about adding new entities and it uses a constructor function for it's product entity.</p>
  
  <p>However I have many entity types and I'm not going to write a constructor function for each one.  This is how I am creating a new entity (<code>name</code> is the name of the datasource and <code>dataTarget.upshot.upshotData</code> is the list of entities I get back from the GetEntities method
  in coffeeScript...</p>
  
  <pre><code>newItem = {}
  for field, def of upshot.metadata(upshot.dataSources[name]._entityType).fields
      do (field, def) -&gt;
      if def.array
          newItem[field] = new ko.observableArray()
      else
          newItem[field] = new ko.observable()
          upshot.addEntityProperties newItem, upshot.dataSources[name]._entityType
          dataTarget.upshot.upshotData.push newItem 
  </code></pre>
  
  <p>my question is if this is the best way to do it or am I missing something?  I'm surprised that upshot does not seem to have a createEntity method.</p>
  
  <p>in javascript...</p>
  
  <pre><code>newItem = {};
  _ref = upshot.metadata(upshot.dataSources[name]._entityType).fields;
  _fn = function(field, def) {
      if (def.array) {
         return newItem[field] = new ko.observableArray();
      } else {
         return newItem[field] = new ko.observable();
      }
  };
        for (field in _ref) {
          def = _ref[field];
          _fn(field, def);
        }
        upshot.addEntityProperties(newItem, upshot.dataSources[name]._entityType);
        dataTarget.upshot.upshotData.push(newItem);
  </code></pre>