Remove assertIsModel and isDataSource

Use `instanceof` operator instead:

  ModelCtor.prototype instanceof loopback.Model
  dataSource instanceof loopback.DataSource
This commit is contained in:
Miroslav Bajtoš 2014-06-06 10:30:03 +02:00
parent 51e977de9b
commit 1b11060991
1 changed files with 5 additions and 15 deletions

View File

@ -115,7 +115,8 @@ app.disuse = function (route) {
app.model = function (Model, config) {
if(arguments.length === 1) {
assertIsModel(Model);
assert(Model.prototype instanceof loopback.Model,
'Model must be a descendant of loopback.Model');
if(Model.sharedClass) {
this.remotes().addClass(Model.sharedClass);
}
@ -165,14 +166,6 @@ app.model = function (Model, config) {
};
function assertIsModel(Model) {
assert(typeof Model === 'function',
'Model must be a function / constructor');
assert(Model.modelName, 'Model must have a "modelName" property');
assert(Model.prototype instanceof loopback.Model,
'Model must be a descendant of loopback.Model');
}
/**
* Get the models exported by the app. Returns only models defined using `app.model()`
*
@ -605,7 +598,8 @@ function dataSourcesFromConfig(config, connectorRegistry) {
}
function configureModel(ModelCtor, config, app) {
assertIsModel(ModelCtor);
assert(ModelCtor.prototype instanceof loopback.Model,
'Model must be a descendant of loopback.Model');
var dataSource = config.dataSource;
@ -613,7 +607,7 @@ function configureModel(ModelCtor, config, app) {
dataSource = app.dataSources[dataSource];
}
assert(isDataSource(dataSource),
assert(dataSource instanceof DataSource,
ModelCtor.modelName + ' is referencing a dataSource that does not exist: "' +
config.dataSource +'"');
@ -692,10 +686,6 @@ function tryReadDir() {
}
}
function isDataSource(obj) {
return obj instanceof DataSource;
}
function tryReadConfig(cwd, fileName) {
try {
return require(path.join(cwd, fileName + '.json'));