Remove assertIsModel and isDataSource
Use `instanceof` operator instead: ModelCtor.prototype instanceof loopback.Model dataSource instanceof loopback.DataSource
This commit is contained in:
parent
51e977de9b
commit
1b11060991
|
@ -115,7 +115,8 @@ app.disuse = function (route) {
|
||||||
|
|
||||||
app.model = function (Model, config) {
|
app.model = function (Model, config) {
|
||||||
if(arguments.length === 1) {
|
if(arguments.length === 1) {
|
||||||
assertIsModel(Model);
|
assert(Model.prototype instanceof loopback.Model,
|
||||||
|
'Model must be a descendant of loopback.Model');
|
||||||
if(Model.sharedClass) {
|
if(Model.sharedClass) {
|
||||||
this.remotes().addClass(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()`
|
* 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) {
|
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;
|
var dataSource = config.dataSource;
|
||||||
|
|
||||||
|
@ -613,7 +607,7 @@ function configureModel(ModelCtor, config, app) {
|
||||||
dataSource = app.dataSources[dataSource];
|
dataSource = app.dataSources[dataSource];
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(isDataSource(dataSource),
|
assert(dataSource instanceof DataSource,
|
||||||
ModelCtor.modelName + ' is referencing a dataSource that does not exist: "' +
|
ModelCtor.modelName + ' is referencing a dataSource that does not exist: "' +
|
||||||
config.dataSource +'"');
|
config.dataSource +'"');
|
||||||
|
|
||||||
|
@ -692,10 +686,6 @@ function tryReadDir() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDataSource(obj) {
|
|
||||||
return obj instanceof DataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
function tryReadConfig(cwd, fileName) {
|
function tryReadConfig(cwd, fileName) {
|
||||||
try {
|
try {
|
||||||
return require(path.join(cwd, fileName + '.json'));
|
return require(path.join(cwd, fileName + '.json'));
|
||||||
|
|
Loading…
Reference in New Issue