Skip to content
This repository has been archived by the owner on Oct 25, 2018. It is now read-only.

Commit

Permalink
move isInstanceOf to typly and use
Browse files Browse the repository at this point in the history
  • Loading branch information
evlach committed Nov 23, 2015
1 parent 02cb50e commit b85622a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
3 changes: 2 additions & 1 deletion lib/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const uuid = require('uuid');
const PersistenceUtils = require("./PersistenceUtils");
const typly = require("typly");

module.exports = class Entity {
constructor(config)
Expand Down Expand Up @@ -59,7 +60,7 @@ module.exports = class Entity {
{
obj[newKey] = this[key];
}
else if (PersistenceUtils.isInstanceOf(property, Entity))
else if (typly.isInstanceOf(property, Entity))
{
obj[newKey] = property;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = class MetaModel {
}
if(this.entityClass)
{
if (PersistenceUtils.isInstanceOf(entity, this.entityClass) === false)
if (typly.isInstanceOf(entity, this.entityClass) === false)
{
throw new RangeError("row cannot be prepared, unexpected entity class: " + entity.constructor.name);
}
Expand Down
31 changes: 1 addition & 30 deletions lib/PersistenceUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = class PersistenceUtils {
typly.assertNotNull(value);
if (typly.isObject(value))
{
if (PersistenceUtils.isInstanceOf(value, TimeUuid) )
if (typly.isInstanceOf(value, TimeUuid) )
{
return value;
}
Expand Down Expand Up @@ -124,33 +124,4 @@ module.exports = class PersistenceUtils {
});
return obj;
}

static isInstanceOf(_object, _class)
{
if (typeof _object !== "object" || _object == undefined || _object === null)
{
throw TypeError("Not valid input for isInstanceOf");
}
//let hasInstance = _object[Symbol.hasInstance];

let isImplementation = true;
let targetPrototype = _class.prototype;
if (_class.constructor)
{
targetPrototype = new _class();
}
let propNames = Object.getOwnPropertyNames(targetPrototype);
if(propNames.length !== Object.getOwnPropertyNames(_object).length)
{
return false;
}
propNames.forEach(function (propName, idx, array)
{
if (!_object.hasOwnProperty(propName))
{
return false;
}
});
return true;
}
};

0 comments on commit b85622a

Please sign in to comment.