Skip to content

Commit 570552d

Browse files
Update angular-ts template to current SDK API
- Regenerate module_bindings with v2.0.0 codegen (copied from react-ts, same module schema) - Update module source to use current schema API format - Fix withModuleName -> withDatabaseName in app.config.ts - Set noPropertyAccessFromIndexSignature: false in tsconfig.json (avoids TS4111 on row property access from index signatures) - Update spacetimedb dependency to workspace:*
1 parent 8878c5d commit 570552d

22 files changed

Lines changed: 157 additions & 98 deletions

templates/angular-ts/spacetimedb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
13-
"spacetimedb": "1.*"
13+
"spacetimedb": "workspace:*"
1414
}
1515
}

templates/angular-ts/spacetimedb/src/index.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
import { schema, table, t } from 'spacetimedb/server';
22

3-
export const spacetimedb = schema(
4-
table(
5-
{ name: 'person', public: true },
3+
const spacetimedb = schema({
4+
person: table(
5+
{ public: true },
66
{
77
name: t.string(),
88
}
9-
)
10-
);
9+
),
10+
});
11+
export default spacetimedb;
1112

12-
spacetimedb.init((_ctx) => {
13+
export const init = spacetimedb.init(_ctx => {
1314
// Called when the module is initially published
1415
});
1516

16-
spacetimedb.clientConnected((_ctx) => {
17+
export const onConnect = spacetimedb.clientConnected(_ctx => {
1718
// Called every time a new client connects
1819
});
1920

20-
spacetimedb.clientDisconnected((_ctx) => {
21+
export const onDisconnect = spacetimedb.clientDisconnected(_ctx => {
2122
// Called every time a client disconnects
2223
});
2324

24-
spacetimedb.reducer('add', { name: t.string() }, (ctx, { name }) => {
25-
ctx.db.person.insert({ name });
26-
});
25+
export const add = spacetimedb.reducer(
26+
{ name: t.string() },
27+
(ctx, { name }) => {
28+
ctx.db.person.insert({ name });
29+
}
30+
);
2731

28-
spacetimedb.reducer('say_hello', (ctx) => {
32+
export const say_hello = spacetimedb.reducer(ctx => {
2933
for (const person of ctx.db.person.iter()) {
3034
console.info(`Hello, ${person.name}!`);
3135
}

templates/angular-ts/src/app/app.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const appConfig: ApplicationConfig = {
3131
provideSpacetimeDB(
3232
DbConnection.builder()
3333
.withUri(HOST)
34-
.withModuleName(DB_NAME)
34+
.withDatabaseName(DB_NAME)
3535
.withToken(localStorage.getItem('auth_token') || undefined)
3636
.onConnect(onConnect)
3737
.onDisconnect(onDisconnect)

templates/angular-ts/src/module_bindings/add_reducer.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/angular-ts/src/module_bindings/add_type.ts

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/angular-ts/src/module_bindings/index.ts

Lines changed: 49 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/angular-ts/src/module_bindings/init_type.ts

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/angular-ts/src/module_bindings/on_connect_reducer.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/angular-ts/src/module_bindings/on_connect_type.ts

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/angular-ts/src/module_bindings/on_disconnect_reducer.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)