12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = exports.AdaptableController = void 0;
- /*
- AdaptableController.js
- AdaptableController is the base class for all controllers
- that support adapter,
- The super class takes care of creating the right instance for the adapter
- based on the parameters passed
- */
- // _adapter is private, use Symbol
- var _adapter = Symbol();
- class AdaptableController {
- constructor(adapter, appId, options) {
- this.options = options;
- this.appId = appId;
- this.adapter = adapter;
- }
- set adapter(adapter) {
- this.validateAdapter(adapter);
- this[_adapter] = adapter;
- }
- get adapter() {
- return this[_adapter];
- }
- expectedAdapterType() {
- throw new Error('Subclasses should implement expectedAdapterType()');
- }
- validateAdapter(adapter) {
- AdaptableController.validateAdapter(adapter, this);
- }
- static validateAdapter(adapter, self, ExpectedType) {
- if (!adapter) {
- throw new Error(this.constructor.name + ' requires an adapter');
- }
- const Type = ExpectedType || self.expectedAdapterType();
- // Allow skipping for testing
- if (!Type) {
- return;
- }
- // 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
- };
- }
- return obj;
- }, {});
- if (Object.keys(mismatches).length > 0) {
- throw new Error("Adapter prototype don't match expected prototype", adapter, mismatches);
- }
- }
- }
- exports.AdaptableController = AdaptableController;
- var _default = exports.default = AdaptableController;
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfYWRhcHRlciIsIlN5bWJvbCIsIkFkYXB0YWJsZUNvbnRyb2xsZXIiLCJjb25zdHJ1Y3RvciIsImFkYXB0ZXIiLCJhcHBJZCIsIm9wdGlvbnMiLCJ2YWxpZGF0ZUFkYXB0ZXIiLCJleHBlY3RlZEFkYXB0ZXJUeXBlIiwiRXJyb3IiLCJzZWxmIiwiRXh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