From 569899169128b7eb24c6f175ca16d8172c7456b8 Mon Sep 17 00:00:00 2001 From: HSReina Date: Wed, 13 Mar 2024 00:02:51 +0900 Subject: [PATCH] Fix issue where some Typescript based project transpiler might mangle the name (#35) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: GĂ©rald Divoux --- src/reducer.ts | 6 +++++- src/spacetimedb.ts | 9 +++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/reducer.ts b/src/reducer.ts index 21db8bb..56eb7bb 100644 --- a/src/reducer.ts +++ b/src/reducer.ts @@ -1,7 +1,11 @@ import { SpacetimeDBClient } from "./spacetimedb"; -export type ReducerClass = { new (...args: any[]): Reducer }; +export type ReducerClass = { + new (...args: any[]): Reducer; + reducerName: string; +}; export class Reducer { + public static reducerName: string; public call(..._args: any[]): void { throw "not implemented"; } diff --git a/src/spacetimedb.ts b/src/spacetimedb.ts index 5d7d1ba..72f199d 100644 --- a/src/spacetimedb.ts +++ b/src/spacetimedb.ts @@ -713,7 +713,7 @@ export class SpacetimeDBClient { * @param table Component to be registered */ public static registerTable(table: DatabaseTableClass) { - this.tableClasses.set(table.name, table); + this.tableClasses.set(table.tableName, table); } /** @@ -722,7 +722,7 @@ export class SpacetimeDBClient { */ public static registerTables(...tables: DatabaseTableClass[]) { for (const table of tables) { - this.tableClasses.set(table.name, table); + this.registerTable(table); } } @@ -732,7 +732,7 @@ export class SpacetimeDBClient { * @param reducer Reducer to be registered */ public static registerReducer(reducer: ReducerClass) { - this.reducerClasses.set(reducer.name, reducer); + this.reducerClasses.set(reducer.reducerName + "Reducer", reducer); } /** @@ -741,9 +741,10 @@ export class SpacetimeDBClient { */ public static registerReducers(...reducers: ReducerClass[]) { for (const reducer of reducers) { - this.reducerClasses.set(reducer.name, reducer); + this.registerReducer(reducer); } } + /** * Subscribe to a set of queries, to be notified when rows which match those queries are altered. *