Add subscription handlers in constructor

Move the calls to add subscrition handlers into the constructor of
Controller to reduce the amount of code in the start logic.
This commit is contained in:
Hornwitser committed 2023-11-18 22:12:14 +01:00
1 parent 60f09b11f9
commit 2c9b07b8d6
1 file changed
+8 -8
+8 -8
View File
@@ -110,6 +110,14 @@ export default class Controller {
this.wsServer = new WsServer(this); this.wsServer = new WsServer(this);
this.userManager = new UserManager(this.config); this.userManager = new UserManager(this.config);
this.subscriptions = new lib.SubscriptionController(this); this.subscriptions = new lib.SubscriptionController(this);
// Handle subscriptions for all internal properties
this.subscriptions.handle(lib.HostUpdateEvent);
this.subscriptions.handle(lib.InstanceDetailsUpdateEvent);
this.subscriptions.handle(lib.InstanceSaveListUpdateEvent);
this.subscriptions.handle(lib.ModPackUpdateEvent);
this.subscriptions.handle(lib.ModUpdateEvent);
this.subscriptions.handle(lib.UserUpdateEvent);
} }
async start(args: ControllerArgs) { async start(args: ControllerArgs) {
@@ -240,14 +248,6 @@ export default class Controller {
this.app.locals.mainBundle = manifest["main.js"] || "no_web_build"; this.app.locals.mainBundle = manifest["main.js"] || "no_web_build";
} }
// Handle subscriptions for all internal properties
this.subscriptions.handle(lib.HostUpdateEvent);
this.subscriptions.handle(lib.InstanceDetailsUpdateEvent);
this.subscriptions.handle(lib.InstanceSaveListUpdateEvent);
this.subscriptions.handle(lib.ModPackUpdateEvent);
this.subscriptions.handle(lib.ModUpdateEvent);
this.subscriptions.handle(lib.UserUpdateEvent);
// Load plugins // Load plugins
await this.loadPlugins(); await this.loadPlugins();