@@ -13,7 +13,6 @@ var _adapter = Symbol();
|
||||
import Config from '../Config';
|
||||
|
||||
export class AdaptableController {
|
||||
|
||||
constructor(adapter, appId, options) {
|
||||
this.options = options;
|
||||
this.appId = appId;
|
||||
@@ -34,7 +33,7 @@ export class AdaptableController {
|
||||
}
|
||||
|
||||
expectedAdapterType() {
|
||||
throw new Error("Subclasses should implement expectedAdapterType()");
|
||||
throw new Error('Subclasses should implement expectedAdapterType()');
|
||||
}
|
||||
|
||||
validateAdapter(adapter) {
|
||||
@@ -43,7 +42,7 @@ export class AdaptableController {
|
||||
|
||||
static validateAdapter(adapter, self, ExpectedType) {
|
||||
if (!adapter) {
|
||||
throw new Error(this.constructor.name + " requires an adapter");
|
||||
throw new Error(this.constructor.name + ' requires an adapter');
|
||||
}
|
||||
|
||||
const Type = ExpectedType || self.expectedAdapterType();
|
||||
@@ -53,20 +52,27 @@ export class AdaptableController {
|
||||
}
|
||||
|
||||
// Makes sure the prototype matches
|
||||
const mismatches = Object.getOwnPropertyNames(Type.prototype).reduce((obj, key) => {
|
||||
const adapterType = typeof adapter[key];
|
||||
const expectedType = typeof Type.prototype[key];
|
||||
if (adapterType !== expectedType) {
|
||||
obj[key] = {
|
||||
expected: expectedType,
|
||||
actual: adapterType
|
||||
const mismatches = Object.getOwnPropertyNames(Type.prototype).reduce(
|
||||
(obj, key) => {
|
||||
const adapterType = typeof adapter[key];
|
||||
const expectedType = typeof Type.prototype[key];
|
||||
if (adapterType !== expectedType) {
|
||||
obj[key] = {
|
||||
expected: expectedType,
|
||||
actual: adapterType,
|
||||
};
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}, {});
|
||||
return obj;
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
if (Object.keys(mismatches).length > 0) {
|
||||
throw new Error("Adapter prototype don't match expected prototype", adapter, mismatches);
|
||||
throw new Error(
|
||||
"Adapter prototype don't match expected prototype",
|
||||
adapter,
|
||||
mismatches
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user