lib/viewmodel.js
function ViewModel (attr, repository, version) {
  if (!repository) {
    var errMsg = 'Please pass in a valid repository';
    console.log(errMsg);
    throw new Error(errMsg);
  }

  for (var f in Repository.prototype) {
    if (!_.isFunction(repository[f])) {
      var errMsg = 'Please pass in a valid repository';
      console.log(errMsg);
      throw new Error(errMsg);
    }
  }

  if (attr.id) {
    this.id = _.clone(attr.id);
  }

  // version addition, used by elasticsearch6, null means a new model
  if (version !== undefined)
    this.version = _.clone(version);

  this.actionOnCommit = 'create';
  this.repository = repository;

  this.attributes = _.cloneDeep(attr);
}
function ViewModel (attr, repository, version) {
  if (!repository) {
    var errMsg = 'Please pass in a valid repository';
    console.log(errMsg);
    throw new Error(errMsg);
  }

  for (var f in Repository.prototype) {
    if (!_.isFunction(repository[f])) {
      var errMsg = 'Please pass in a valid repository';
      console.log(errMsg);
      throw new Error(errMsg);
    }
  }

  if (attr.id) {
    this.id = _.clone(attr.id);
  }

  // version addition, used by elasticsearch6, null means a new model
  if (version !== undefined)
    this.version = _.clone(version);

  this.actionOnCommit = 'create';
  this.repository = repository;

  this.attributes = _.cloneDeep(attr);
}
ViewModel constructor
@param {String} attr The attributes of this viewmodel instance.