Workaround a circular dependency

Change-type: patch
This commit is contained in:
Pagan Gazzard 2020-04-08 17:03:07 +01:00
parent d402bebee1
commit a59af6abe8
3 changed files with 10 additions and 10 deletions

View File

@ -44,7 +44,6 @@ export interface APIBinderConstructOpts {
config: Config; config: Config;
// FIXME: Remove this // FIXME: Remove this
db: Database; db: Database;
deviceState: DeviceState;
eventTracker: EventTracker; eventTracker: EventTracker;
logger: Logger; logger: Logger;
} }
@ -94,20 +93,18 @@ export class APIBinder {
private targetStateFetchErrors = 0; private targetStateFetchErrors = 0;
private readyForUpdates = false; private readyForUpdates = false;
public constructor({ public constructor({ config, eventTracker, logger }: APIBinderConstructOpts) {
config,
deviceState,
eventTracker,
logger,
}: APIBinderConstructOpts) {
this.config = config; this.config = config;
this.deviceState = deviceState;
this.eventTracker = eventTracker; this.eventTracker = eventTracker;
this.logger = logger; this.logger = logger;
this.router = this.createAPIBinderRouter(this); this.router = this.createAPIBinderRouter(this);
} }
public setDeviceState(deviceState: DeviceState) {
this.deviceState = deviceState;
}
public async healthcheck() { public async healthcheck() {
const { const {
appUpdatePollInterval, appUpdatePollInterval,

View File

@ -43,7 +43,6 @@ export class Supervisor {
this.apiBinder = new APIBinder({ this.apiBinder = new APIBinder({
config: this.config, config: this.config,
db: this.db, db: this.db,
deviceState: this.deviceState,
eventTracker: this.eventTracker, eventTracker: this.eventTracker,
logger: this.logger, logger: this.logger,
}); });
@ -54,6 +53,8 @@ export class Supervisor {
logger: this.logger, logger: this.logger,
apiBinder: this.apiBinder, apiBinder: this.apiBinder,
}); });
// workaround the circular dependency
this.apiBinder.setDeviceState(this.deviceState);
// FIXME: rearchitect proxyvisor to avoid this circular dependency // FIXME: rearchitect proxyvisor to avoid this circular dependency
// by storing current state and having the APIBinder query and report it / provision devices // by storing current state and having the APIBinder query and report it / provision devices

View File

@ -34,7 +34,6 @@ const initModels = async (obj: Dictionary<any>, filename: string) => {
config: obj.config, config: obj.config,
logger: obj.logger, logger: obj.logger,
eventTracker: obj.eventTracker, eventTracker: obj.eventTracker,
deviceState: obj.deviceState,
}); });
obj.deviceState = new DeviceState({ obj.deviceState = new DeviceState({
@ -44,6 +43,9 @@ const initModels = async (obj: Dictionary<any>, filename: string) => {
logger: obj.logger, logger: obj.logger,
apiBinder: obj.apiBinder, apiBinder: obj.apiBinder,
}); });
obj.apiBinder.setDeviceState(obj.deviceState);
await obj.db.init(); await obj.db.init();
await obj.config.init(); await obj.config.init();
await obj.apiBinder.initClient(); // Initializes the clients but doesn't trigger provisioning await obj.apiBinder.initClient(); // Initializes the clients but doesn't trigger provisioning