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.
This commit is contained in:
Hornwitser committed 2024-09-04 13:32:38 +02:00
1 parent 6226a45d0b
commit 95396ff1c3
1 file changed
+4 -4
+4 -4
View File
@@ -102,12 +102,12 @@ export default class Controller {
const systems = new lib.SubscribableDatastore(...await new lib.JsonIdDatastoreProvider( const systems = new lib.SubscribableDatastore(...await new lib.JsonIdDatastoreProvider(
path.join(databaseDirectory, "systems.json"), path.join(databaseDirectory, "systems.json"),
lib.SystemInfo.fromJSON lib.SystemInfo.fromJSON.bind(lib.SystemInfo)
).bootstrap()); ).bootstrap());
const hosts = new lib.SubscribableDatastore(...await new lib.JsonIdDatastoreProvider( const hosts = new lib.SubscribableDatastore(...await new lib.JsonIdDatastoreProvider(
path.join(databaseDirectory, "hosts.json"), path.join(databaseDirectory, "hosts.json"),
HostInfo.fromJSON, HostInfo.fromJSON.bind(HostInfo),
this.migrateHosts, this.finaliseHosts, this.migrateHosts, this.finaliseHosts,
).bootstrap()); ).bootstrap());
@@ -119,12 +119,12 @@ export default class Controller {
const saves = new lib.SubscribableDatastore(...await new lib.JsonIdDatastoreProvider( const saves = new lib.SubscribableDatastore(...await new lib.JsonIdDatastoreProvider(
path.join(databaseDirectory, "saves.json"), path.join(databaseDirectory, "saves.json"),
lib.SaveDetails.fromJSON lib.SaveDetails.fromJSON.bind(lib.SaveDetails)
).bootstrap()); ).bootstrap());
const modPacks = new lib.SubscribableDatastore(...await new lib.JsonIdDatastoreProvider( const modPacks = new lib.SubscribableDatastore(...await new lib.JsonIdDatastoreProvider(
path.join(databaseDirectory, "mod-packs.json"), path.join(databaseDirectory, "mod-packs.json"),
lib.ModPack.fromJSON lib.ModPack.fromJSON.bind(lib.ModPack)
).bootstrap()); ).bootstrap());
const userManager = new UserManager(config); const userManager = new UserManager(config);