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

View File

@ -43,7 +43,6 @@ export class Supervisor {
this.apiBinder = new APIBinder({
config: this.config,
db: this.db,
deviceState: this.deviceState,
eventTracker: this.eventTracker,
logger: this.logger,
});
@ -54,6 +53,8 @@ export class Supervisor {
logger: this.logger,
apiBinder: this.apiBinder,
});
// workaround the circular dependency
this.apiBinder.setDeviceState(this.deviceState);
// FIXME: rearchitect proxyvisor to avoid this circular dependency
// 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,
logger: obj.logger,
eventTracker: obj.eventTracker,
deviceState: obj.deviceState,
});
obj.deviceState = new DeviceState({
@ -44,6 +43,9 @@ const initModels = async (obj: Dictionary<any>, filename: string) => {
logger: obj.logger,
apiBinder: obj.apiBinder,
});
obj.apiBinder.setDeviceState(obj.deviceState);
await obj.db.init();
await obj.config.init();
await obj.apiBinder.initClient(); // Initializes the clients but doesn't trigger provisioning