Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where some Typescript based project transpiler might mangle the table or Reducer #35

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/reducer.ts
Original file line number Diff line number Diff line change
@@ -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";
}
Expand Down
9 changes: 5 additions & 4 deletions src/spacetimedb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,12 +820,12 @@ export class SpacetimeDBClient {
* @param component Component to be registered
*/
public static registerTable(table: DatabaseTableClass) {
this.tableClasses.set(table.name, table);
this.tableClasses.set(table.tableName, table);
}

public static registerTables(...tables: DatabaseTableClass[]) {
for (const table of tables) {
this.tableClasses.set(table.name, table);
this.registerTable(table);
}
}

Expand All @@ -836,14 +836,15 @@ 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);
}

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.
*
Expand Down
Loading