Remove assertIsModel and isDataSource
Use `instanceof` operator instead: ModelCtor.prototype instanceof loopback.Model dataSource instanceof loopback.DataSource
This commit is contained in:
parent
fc0fad4a9f
commit
19425b8fd9
|
@ -141,7 +141,8 @@ app.model = function (Model, config) {
|
|||
configureModel(Model, config, this);
|
||||
isPublic = config.public !== false;
|
||||
} else {
|
||||
assertIsModel(Model);
|
||||
assert(Model.prototype instanceof loopback.Model,
|
||||
'Model must be a descendant of loopback.Model');
|
||||
}
|
||||
|
||||
var modelName = Model.modelName;
|
||||
|
@ -163,14 +164,6 @@ app.model = function (Model, config) {
|
|||
return Model;
|
||||
};
|
||||
|
||||
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'));
|
||||
|
|
Loading…
Reference in New Issue