diff --git a/crates/bindings-typescript/examples/basic-react/src/App.tsx b/crates/bindings-typescript/examples/basic-react/src/App.tsx index 794e88af3d6..f320c09d0aa 100644 --- a/crates/bindings-typescript/examples/basic-react/src/App.tsx +++ b/crates/bindings-typescript/examples/basic-react/src/App.tsx @@ -1,22 +1,24 @@ import { useState } from 'react'; -import { DbConnection, Person } from './module_bindings'; -import { useSpacetimeDB, useTable } from 'spacetimedb/react'; +import { tables, reducers } from './module_bindings'; +import { useSpacetimeDB, useTable, useReducer } from 'spacetimedb/react'; function App() { const [name, setName] = useState(''); - const conn = useSpacetimeDB(); + const conn = useSpacetimeDB(); const { isActive: connected } = conn; // Subscribe to all people in the database - const { rows: people } = useTable('person'); + const [people] = useTable(tables.person); + + const addReducer = useReducer(reducers.add); const addPerson = (e: React.FormEvent) => { e.preventDefault(); if (!name.trim() || !connected) return; // Call the add reducer - conn.reducers.add(name); + addReducer({ name: name }); setName(''); }; diff --git a/crates/bindings-typescript/examples/basic-react/src/main.tsx b/crates/bindings-typescript/examples/basic-react/src/main.tsx index 0cfb34e144b..2d43ef4495a 100644 --- a/crates/bindings-typescript/examples/basic-react/src/main.tsx +++ b/crates/bindings-typescript/examples/basic-react/src/main.tsx @@ -6,7 +6,7 @@ import { SpacetimeDBProvider } from 'spacetimedb/react'; import { DbConnection, ErrorContext } from './module_bindings/index.ts'; const HOST = import.meta.env.VITE_SPACETIMEDB_HOST ?? 'ws://localhost:3000'; -const DB_NAME = import.meta.env.VITE_SPACETIMEDB_DB_NAME ?? 'my-db'; +const DB_NAME = import.meta.env.VITE_SPACETIMEDB_DB_NAME ?? 'basic-react'; const onConnect = (_conn: DbConnection, identity: Identity, token: string) => { localStorage.setItem('auth_token', token); diff --git a/crates/bindings-typescript/examples/basic-react/src/module_bindings/index.ts b/crates/bindings-typescript/examples/basic-react/src/module_bindings/index.ts index 2eea2e6927b..37d22cfc611 100644 --- a/crates/bindings-typescript/examples/basic-react/src/module_bindings/index.ts +++ b/crates/bindings-typescript/examples/basic-react/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.11.0 (commit 9b043d1d010681538a74764cfe78d660de6838ac). +// This was generated using spacetimedb cli version 1.11.0 (commit 492e591845db8b174ee885b74294cb4ecbf655dc). /* eslint-disable */ /* tslint:disable */ @@ -31,14 +31,14 @@ import { } from 'spacetimedb'; // Import and reexport all reducer arg types -import OnConnect from './on_connect_reducer'; -export { OnConnect }; -import OnDisconnect from './on_disconnect_reducer'; -export { OnDisconnect }; -import Add from './add_reducer'; -export { Add }; -import SayHello from './say_hello_reducer'; -export { SayHello }; +import OnConnectReducer from './on_connect_reducer'; +export { OnConnectReducer }; +import OnDisconnectReducer from './on_disconnect_reducer'; +export { OnDisconnectReducer }; +import AddReducer from './add_reducer'; +export { AddReducer }; +import SayHelloReducer from './say_hello_reducer'; +export { SayHelloReducer }; // Import and reexport all procedure arg types @@ -74,8 +74,8 @@ const tablesSchema = __schema( /** The schema information for all reducers in this module. This is defined the same way as the reducers would have been defined in the server, except the body of the reducer is omitted in code generation. */ const reducersSchema = __reducers( - __reducerSchema('add', Add), - __reducerSchema('say_hello', SayHello) + __reducerSchema('add', AddReducer), + __reducerSchema('say_hello', SayHelloReducer) ); /** The schema information for all procedures in this module. This is defined the same way as the procedures would have been defined in the server. */ diff --git a/crates/bindings-typescript/examples/empty/src/module_bindings/index.ts b/crates/bindings-typescript/examples/empty/src/module_bindings/index.ts index 2eea2e6927b..37d22cfc611 100644 --- a/crates/bindings-typescript/examples/empty/src/module_bindings/index.ts +++ b/crates/bindings-typescript/examples/empty/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.11.0 (commit 9b043d1d010681538a74764cfe78d660de6838ac). +// This was generated using spacetimedb cli version 1.11.0 (commit 492e591845db8b174ee885b74294cb4ecbf655dc). /* eslint-disable */ /* tslint:disable */ @@ -31,14 +31,14 @@ import { } from 'spacetimedb'; // Import and reexport all reducer arg types -import OnConnect from './on_connect_reducer'; -export { OnConnect }; -import OnDisconnect from './on_disconnect_reducer'; -export { OnDisconnect }; -import Add from './add_reducer'; -export { Add }; -import SayHello from './say_hello_reducer'; -export { SayHello }; +import OnConnectReducer from './on_connect_reducer'; +export { OnConnectReducer }; +import OnDisconnectReducer from './on_disconnect_reducer'; +export { OnDisconnectReducer }; +import AddReducer from './add_reducer'; +export { AddReducer }; +import SayHelloReducer from './say_hello_reducer'; +export { SayHelloReducer }; // Import and reexport all procedure arg types @@ -74,8 +74,8 @@ const tablesSchema = __schema( /** The schema information for all reducers in this module. This is defined the same way as the reducers would have been defined in the server, except the body of the reducer is omitted in code generation. */ const reducersSchema = __reducers( - __reducerSchema('add', Add), - __reducerSchema('say_hello', SayHello) + __reducerSchema('add', AddReducer), + __reducerSchema('say_hello', SayHelloReducer) ); /** The schema information for all procedures in this module. This is defined the same way as the procedures would have been defined in the server. */ diff --git a/crates/bindings-typescript/examples/quickstart-chat/src/module_bindings/index.ts b/crates/bindings-typescript/examples/quickstart-chat/src/module_bindings/index.ts index 9823f6064ea..7b27db22ea9 100644 --- a/crates/bindings-typescript/examples/quickstart-chat/src/module_bindings/index.ts +++ b/crates/bindings-typescript/examples/quickstart-chat/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.11.0 (commit 9b043d1d010681538a74764cfe78d660de6838ac). +// This was generated using spacetimedb cli version 1.11.0 (commit 492e591845db8b174ee885b74294cb4ecbf655dc). /* eslint-disable */ /* tslint:disable */ @@ -31,14 +31,14 @@ import { } from 'spacetimedb'; // Import and reexport all reducer arg types -import IdentityConnected from './identity_connected_reducer'; -export { IdentityConnected }; -import IdentityDisconnected from './identity_disconnected_reducer'; -export { IdentityDisconnected }; -import SendMessage from './send_message_reducer'; -export { SendMessage }; -import SetName from './set_name_reducer'; -export { SetName }; +import IdentityConnectedReducer from './identity_connected_reducer'; +export { IdentityConnectedReducer }; +import IdentityDisconnectedReducer from './identity_disconnected_reducer'; +export { IdentityDisconnectedReducer }; +import SendMessageReducer from './send_message_reducer'; +export { SendMessageReducer }; +import SetNameReducer from './set_name_reducer'; +export { SetNameReducer }; // Import and reexport all procedure arg types @@ -84,8 +84,8 @@ const tablesSchema = __schema( /** The schema information for all reducers in this module. This is defined the same way as the reducers would have been defined in the server, except the body of the reducer is omitted in code generation. */ const reducersSchema = __reducers( - __reducerSchema('send_message', SendMessage), - __reducerSchema('set_name', SetName) + __reducerSchema('send_message', SendMessageReducer), + __reducerSchema('set_name', SetNameReducer) ); /** The schema information for all procedures in this module. This is defined the same way as the procedures would have been defined in the server. */ diff --git a/crates/bindings-typescript/src/sdk/client_api/index.ts b/crates/bindings-typescript/src/sdk/client_api/index.ts index 9be499afa34..1dffeccfdd1 100644 --- a/crates/bindings-typescript/src/sdk/client_api/index.ts +++ b/crates/bindings-typescript/src/sdk/client_api/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.11.0 (commit 9b043d1d010681538a74764cfe78d660de6838ac). +// This was generated using spacetimedb cli version 1.11.0 (commit 492e591845db8b174ee885b74294cb4ecbf655dc). /* eslint-disable */ /* tslint:disable */ diff --git a/crates/bindings-typescript/test-app/src/module_bindings/index.ts b/crates/bindings-typescript/test-app/src/module_bindings/index.ts index ada114319ec..46ef1b99735 100644 --- a/crates/bindings-typescript/test-app/src/module_bindings/index.ts +++ b/crates/bindings-typescript/test-app/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.11.0 (commit 9b043d1d010681538a74764cfe78d660de6838ac). +// This was generated using spacetimedb cli version 1.11.0 (commit 492e591845db8b174ee885b74294cb4ecbf655dc). /* eslint-disable */ /* tslint:disable */ @@ -31,8 +31,8 @@ import { } from '../../../src/index'; // Import and reexport all reducer arg types -import CreatePlayer from './create_player_reducer'; -export { CreatePlayer }; +import CreatePlayerReducer from './create_player_reducer'; +export { CreatePlayerReducer }; // Import and reexport all procedure arg types @@ -100,7 +100,7 @@ const tablesSchema = __schema( /** The schema information for all reducers in this module. This is defined the same way as the reducers would have been defined in the server, except the body of the reducer is omitted in code generation. */ const reducersSchema = __reducers( - __reducerSchema('create_player', CreatePlayer) + __reducerSchema('create_player', CreatePlayerReducer) ); /** The schema information for all procedures in this module. This is defined the same way as the procedures would have been defined in the server. */ diff --git a/crates/codegen/src/typescript.rs b/crates/codegen/src/typescript.rs index 8fec35dbd80..d1f9343a362 100644 --- a/crates/codegen/src/typescript.rs +++ b/crates/codegen/src/typescript.rs @@ -808,7 +808,7 @@ fn table_module_name(table_name: &Identifier) -> String { } fn reducer_args_type_name(reducer_name: &Identifier) -> String { - reducer_name.deref().to_case(Case::Pascal) + reducer_name.deref().to_case(Case::Pascal) + "Reducer" } fn procedure_args_type_name(reducer_name: &Identifier) -> String { diff --git a/crates/codegen/tests/snapshots/codegen__codegen_typescript.snap b/crates/codegen/tests/snapshots/codegen__codegen_typescript.snap index 33480625ee7..7fadaef6c51 100644 --- a/crates/codegen/tests/snapshots/codegen__codegen_typescript.snap +++ b/crates/codegen/tests/snapshots/codegen__codegen_typescript.snap @@ -252,34 +252,34 @@ import { } from "spacetimedb"; // Import and reexport all reducer arg types -import Add from "./add_reducer"; -export { Add }; -import AddPlayer from "./add_player_reducer"; -export { AddPlayer }; -import AddPrivate from "./add_private_reducer"; -export { AddPrivate }; -import AssertCallerIdentityIsModuleIdentity from "./assert_caller_identity_is_module_identity_reducer"; -export { AssertCallerIdentityIsModuleIdentity }; -import ClientConnected from "./client_connected_reducer"; -export { ClientConnected }; -import DeletePlayer from "./delete_player_reducer"; -export { DeletePlayer }; -import DeletePlayersByName from "./delete_players_by_name_reducer"; -export { DeletePlayersByName }; -import ListOverAge from "./list_over_age_reducer"; -export { ListOverAge }; -import LogModuleIdentity from "./log_module_identity_reducer"; -export { LogModuleIdentity }; -import QueryPrivate from "./query_private_reducer"; -export { QueryPrivate }; -import RepeatingTest from "./repeating_test_reducer"; -export { RepeatingTest }; -import SayHello from "./say_hello_reducer"; -export { SayHello }; -import Test from "./test_reducer"; -export { Test }; -import TestBtreeIndexArgs from "./test_btree_index_args_reducer"; -export { TestBtreeIndexArgs }; +import AddReducer from "./add_reducer"; +export { AddReducer }; +import AddPlayerReducer from "./add_player_reducer"; +export { AddPlayerReducer }; +import AddPrivateReducer from "./add_private_reducer"; +export { AddPrivateReducer }; +import AssertCallerIdentityIsModuleIdentityReducer from "./assert_caller_identity_is_module_identity_reducer"; +export { AssertCallerIdentityIsModuleIdentityReducer }; +import ClientConnectedReducer from "./client_connected_reducer"; +export { ClientConnectedReducer }; +import DeletePlayerReducer from "./delete_player_reducer"; +export { DeletePlayerReducer }; +import DeletePlayersByNameReducer from "./delete_players_by_name_reducer"; +export { DeletePlayersByNameReducer }; +import ListOverAgeReducer from "./list_over_age_reducer"; +export { ListOverAgeReducer }; +import LogModuleIdentityReducer from "./log_module_identity_reducer"; +export { LogModuleIdentityReducer }; +import QueryPrivateReducer from "./query_private_reducer"; +export { QueryPrivateReducer }; +import RepeatingTestReducer from "./repeating_test_reducer"; +export { RepeatingTestReducer }; +import SayHelloReducer from "./say_hello_reducer"; +export { SayHelloReducer }; +import TestReducer from "./test_reducer"; +export { TestReducer }; +import TestBtreeIndexArgsReducer from "./test_btree_index_args_reducer"; +export { TestBtreeIndexArgsReducer }; // Import and reexport all procedure arg types import * as GetMySchemaViaHttpProcedure from "./get_my_schema_via_http_procedure"; @@ -518,19 +518,19 @@ const tablesSchema = __schema( /** The schema information for all reducers in this module. This is defined the same way as the reducers would have been defined in the server, except the body of the reducer is omitted in code generation. */ const reducersSchema = __reducers( - __reducerSchema("add", Add), - __reducerSchema("add_player", AddPlayer), - __reducerSchema("add_private", AddPrivate), - __reducerSchema("assert_caller_identity_is_module_identity", AssertCallerIdentityIsModuleIdentity), - __reducerSchema("delete_player", DeletePlayer), - __reducerSchema("delete_players_by_name", DeletePlayersByName), - __reducerSchema("list_over_age", ListOverAge), - __reducerSchema("log_module_identity", LogModuleIdentity), - __reducerSchema("query_private", QueryPrivate), - __reducerSchema("repeating_test", RepeatingTest), - __reducerSchema("say_hello", SayHello), - __reducerSchema("test", Test), - __reducerSchema("test_btree_index_args", TestBtreeIndexArgs), + __reducerSchema("add", AddReducer), + __reducerSchema("add_player", AddPlayerReducer), + __reducerSchema("add_private", AddPrivateReducer), + __reducerSchema("assert_caller_identity_is_module_identity", AssertCallerIdentityIsModuleIdentityReducer), + __reducerSchema("delete_player", DeletePlayerReducer), + __reducerSchema("delete_players_by_name", DeletePlayersByNameReducer), + __reducerSchema("list_over_age", ListOverAgeReducer), + __reducerSchema("log_module_identity", LogModuleIdentityReducer), + __reducerSchema("query_private", QueryPrivateReducer), + __reducerSchema("repeating_test", RepeatingTestReducer), + __reducerSchema("say_hello", SayHelloReducer), + __reducerSchema("test", TestReducer), + __reducerSchema("test_btree_index_args", TestBtreeIndexArgsReducer), ); /** The schema information for all procedures in this module. This is defined the same way as the procedures would have been defined in the server. */