From 95396ff1c33d05e3d0e294d5c46e826ecdb0842b Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 4 Sep 2024 13:32:38 +0200 Subject: [PATCH] Fix this is not a constructor error on startup When passing methods around they lose their binding to this, which means the fromJSON methods no longer has this be their class. Fix by binding the methods to the class they belong to before passing them on to the datastore. --- packages/controller/src/Controller.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/controller/src/Controller.ts b/packages/controller/src/Controller.ts index 4a18a9cb..ed258b73 100644 --- a/packages/controller/src/Controller.ts +++ b/packages/controller/src/Controller.ts @@ -102,12 +102,12 @@ export default class Controller { const systems = new lib.SubscribableDatastore(...await new lib.JsonIdDatastoreProvider( path.join(databaseDirectory, "systems.json"), - lib.SystemInfo.fromJSON + lib.SystemInfo.fromJSON.bind(lib.SystemInfo) ).bootstrap()); const hosts = new lib.SubscribableDatastore(...await new lib.JsonIdDatastoreProvider( path.join(databaseDirectory, "hosts.json"), - HostInfo.fromJSON, + HostInfo.fromJSON.bind(HostInfo), this.migrateHosts, this.finaliseHosts, ).bootstrap()); @@ -119,12 +119,12 @@ export default class Controller { const saves = new lib.SubscribableDatastore(...await new lib.JsonIdDatastoreProvider( path.join(databaseDirectory, "saves.json"), - lib.SaveDetails.fromJSON + lib.SaveDetails.fromJSON.bind(lib.SaveDetails) ).bootstrap()); const modPacks = new lib.SubscribableDatastore(...await new lib.JsonIdDatastoreProvider( path.join(databaseDirectory, "mod-packs.json"), - lib.ModPack.fromJSON + lib.ModPack.fromJSON.bind(lib.ModPack) ).bootstrap()); const userManager = new UserManager(config);