Skip to content

Commit 1b4d40d

Browse files
committed
doc: Onboarding impr, fixes, consistency, cleanup
refactor: Whats next cleanup, +unity, -bloat Removed redundant text while there refactor: Unity quickstart fixes, impr, prettify refactor: Unity pt1 fixes, impr, prettify fix(README): Rm "see test edits below" ref * !exists refactor(minor): General onboarding cleanup * Shorter, prettier, consistent
1 parent f6d1353 commit 1b4d40d

File tree

7 files changed

+117
-63
lines changed

7 files changed

+117
-63
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ To make changes to our docs, you can open a pull request in this repository. You
1313
git clone ssh://[email protected]/<username>/spacetime-docs
1414
```
1515

16-
3. Make your edits to the docs that you want to make + test them locally (see Testing Your Edits below)
16+
3. Make your edits to the docs that you want to make + test them locally
1717
4. Commit your changes:
1818

1919
```bash

docs/getting-started.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,32 @@
22

33
To develop SpacetimeDB applications locally, you will need to run the Standalone version of the server.
44

5-
1. [Install](/install) the SpacetimeDB CLI (Command Line Interface).
5+
1. [Install](/install) the SpacetimeDB CLI (Command Line Interface)
66
2. Run the start command
77

88
```bash
99
spacetime start
1010
```
1111

12-
The server listens on port `3000` by default. You can change this by using the `--listen-addr` option described below.
12+
The server listens on port `3000` by default, customized via `--listen-addr`.
1313

14-
SSL is not supported in standalone mode.
14+
⚠️ SSL is not supported in standalone mode.
1515

1616
## What's Next?
1717

18-
You are ready to start developing SpacetimeDB modules. We have a quickstart guide for each supported server-side language:
18+
You are ready to start developing SpacetimeDB modules. See below for a quickstart guide for both client and server (module) languages/frameworks.
19+
20+
### Server (Module)
1921

2022
- [Rust](/docs/modules/rust/quickstart)
2123
- [C#](/docs/modules/c-sharp/quickstart)
2224

23-
Then you can write your client application. We have a quickstart guide for each supported client-side language:
25+
**Note:** Rust is [roughly 2x faster](https://faun.dev/c/links/faun/c-vs-rust-vs-go-a-performance-benchmarking-in-kubernetes/) than C#
26+
27+
### Client
2428

2529
- [Rust](/docs/sdks/rust/quickstart)
26-
- [C#](/docs/sdks/c-sharp/quickstart)
30+
- [C# (Standalone)](/docs/sdks/c-sharp/quickstart)
31+
- [C# (Unity)](/docs/unity/part-1)
2732
- [Typescript](/docs/sdks/typescript/quickstart)
28-
- [Python](/docs/sdks/python/quickstart)
29-
30-
We also have a [step-by-step tutorial](/docs/unity/part-1) for building a multiplayer game in Unity3d.
33+
- [Python](/docs/sdks/python/quickstart)

docs/modules/c-sharp/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static partial class Module
4242
{
4343
// We can skip (or explicitly set to zero) auto-incremented fields when creating new rows.
4444
var person = new Person { Name = name, Age = age };
45+
4546
// `Insert()` method is auto-generated and will insert the given row into the table.
4647
person.Insert();
4748
// After insertion, the auto-incremented fields will be populated with their actual values.
@@ -211,8 +212,10 @@ public partial struct Person
211212
212213
// Finds a row in the table with the given value in the `Id` column and returns it, or `null` if no such row exists.
213214
public static Person? FindById(int id);
215+
214216
// Deletes a row in the table with the given value in the `Id` column and returns `true` if the row was found and deleted, or `false` if no such row exists.
215217
public static bool DeleteById(int id);
218+
216219
// Updates a row in the table with the given value in the `Id` column and returns `true` if the row was found and updated, or `false` if no such row exists.
217220
public static bool UpdateById(int oldId, Person newValue);
218221
}

docs/modules/c-sharp/quickstart.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ If you haven't already, start by [installing SpacetimeDB](/install). This will i
1616

1717
## Install .NET 8
1818

19-
Next we need to [install .NET 8 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) so that we can build and publish our module. .NET 8.0 is the earliest to have the `wasi-experimental` workload that we rely on.
19+
Next we need to [install .NET 8 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) so that we can build and publish our module.
20+
21+
You may already have .NET 8 and can be checked:
22+
```bash
23+
dotnet --list-sdks
24+
```
25+
26+
.NET 8.0 is the earliest to have the `wasi-experimental` workload that we rely on, but requires manual activation:
27+
28+
```bash
29+
dotnet workload install wasi-experimental
30+
```
2031

2132
## Project structure
2233

@@ -35,7 +46,11 @@ spacetime init --lang csharp server
3546

3647
## Declare imports
3748

38-
`spacetime init` should have pre-populated `server/Lib.cs` with a trivial module. Clear it out, so we can write a module that's still pretty simple: a bare-bones chat server.
49+
`spacetime init` generated a few files:
50+
51+
1. Open `server/StdbModule.csproj` to generate a .sln file for intellisense/validation support.
52+
2. Open `server/Lib.cs`, a trivial module.
53+
3. Clear it out, so we can write a new module that's still pretty simple: a bare-bones chat server.
3954

4055
To the top of `server/Lib.cs`, add some imports we'll be using:
4156

@@ -235,7 +250,7 @@ public static void OnDisconnect(DbEventArgs dbEventArgs)
235250
else
236251
{
237252
// User does not exist, log warning
238-
Log($"Warning: No user found for disconnected client.");
253+
Log("Warning: No user found for disconnected client.");
239254
}
240255
}
241256
```
@@ -250,12 +265,16 @@ From the `quickstart-chat` directory, run:
250265
spacetime publish --project-path server <module-name>
251266
```
252267

268+
```bash
269+
npm i wasm-opt -g
270+
```
271+
253272
## Call Reducers
254273

255274
You can use the CLI (command line interface) to run reducers. The arguments to the reducer are passed in JSON format.
256275

257276
```bash
258-
spacetime call <module-name> send_message '["Hello, World!"]'
277+
spacetime call <module-name> send_message "Hello, World!"
259278
```
260279

261280
Once we've called our `send_message` reducer, we can check to make sure it ran by running the `logs` command.
@@ -288,4 +307,4 @@ spacetime sql <module-name> "SELECT * FROM Message"
288307

289308
You've just set up your first database in SpacetimeDB! The next step would be to create a client module that interacts with this module. You can use any of SpacetimDB's supported client languages to do this. Take a look at the quick start guide for your client language of choice: [Rust](/docs/languages/rust/rust-sdk-quickstart-guide), [C#](/docs/languages/csharp/csharp-sdk-quickstart-guide), [TypeScript](/docs/languages/typescript/typescript-sdk-quickstart-guide) or [Python](/docs/languages/python/python-sdk-quickstart-guide).
290309

291-
If you are planning to use SpacetimeDB with the Unity3d game engine, you can skip right to the [Unity Comprehensive Tutorial](/docs/unity/part-1) or check out our example game, [BitcraftMini](/docs/unity/part-3).
310+
If you are planning to use SpacetimeDB with the Unity game engine, you can skip right to the [Unity Comprehensive Tutorial](/docs/unity/part-1) or check out our example game, [BitcraftMini](/docs/unity/part-3).

docs/modules/rust/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,4 @@ You can find the full code for this module [in the SpacetimeDB module examples](
269269

270270
You've just set up your first database in SpacetimeDB! The next step would be to create a client module that interacts with this module. You can use any of SpacetimDB's supported client languages to do this. Take a look at the quickstart guide for your client language of choice: [Rust](/docs/sdks/rust/quickstart), [C#](/docs/sdks/c-sharp/quickstart), [TypeScript](/docs/sdks/typescript/quickstart) or [Python](/docs/sdks/python/quickstart).
271271

272-
If you are planning to use SpacetimeDB with the Unity3d game engine, you can skip right to the [Unity Comprehensive Tutorial](/docs/unity/part-1) or check out our example game, [BitcraftMini](/docs/unity/part-3).
272+
If you are planning to use SpacetimeDB with the Unity game engine, you can skip right to the [Unity Comprehensive Tutorial](/docs/unity/part-1) or check out our example game, [BitcraftMini](/docs/unity/part-3).

docs/sdks/c-sharp/quickstart.md

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# C# Client SDK Quick Start
22

3-
In this guide we'll show you how to get up and running with a simple SpacetimDB app with a client written in C#.
3+
In this guide we'll show you how to get up and running with a simple SpacetimeDB app with a client written in C#.
44

5-
We'll implement a command-line client for the module created in our Rust or C# Module Quickstart guides. Make sure you follow one of these guides before you start on this one.
5+
We'll implement a command-line client for the module created in our [Rust](../../modules/rust/quickstart.md) or [C# Module](../../modules/c-sharp/quickstart.md) Quickstart guides. Ensure you followed one of these guides before continuing.
66

77
## Project structure
88

@@ -12,7 +12,7 @@ Enter the directory `quickstart-chat` you created in the [Rust Module Quickstart
1212
cd quickstart-chat
1313
```
1414

15-
Within it, create a new C# console application project called `client` using either Visual Studio or the .NET CLI:
15+
Within it, create a new C# console application project called `client` using either Visual Studio, Rider or the .NET CLI:
1616

1717
```bash
1818
dotnet new console -o client
@@ -22,7 +22,7 @@ Open the project in your IDE of choice.
2222

2323
## Add the NuGet package for the C# SpacetimeDB SDK
2424

25-
Add the `SpacetimeDB.ClientSDK` [NuGet package](https://www.nuget.org/packages/spacetimedbsdk) using Visual Studio NuGet package manager or via the .NET CLI
25+
Add the `SpacetimeDB.ClientSDK` [NuGet package](https://www.nuget.org/packages/spacetimedbsdk) using Visual Studio or Rider _NuGet Package Manager_ or via the .NET CLI:
2626

2727
```bash
2828
dotnet add package SpacetimeDB.ClientSDK
@@ -39,7 +39,7 @@ mkdir -p client/module_bindings
3939
spacetime generate --lang csharp --out-dir client/module_bindings --project-path server
4040
```
4141

42-
Take a look inside `client/module_bindings`. The CLI should have generated five files:
42+
Take a look inside `client/module_bindings`. The CLI should have generated five files under `module_bindings`:
4343

4444
```
4545
module_bindings
@@ -65,8 +65,10 @@ We will also need to create some global variables that will be explained when we
6565
```csharp
6666
// our local client SpacetimeDB identity
6767
Identity? local_identity = null;
68+
6869
// declare a thread safe queue to store commands in format (command, args)
6970
ConcurrentQueue<(string,string)> input_queue = new ConcurrentQueue<(string, string)>();
71+
7072
// declare a threadsafe cancel token to cancel the process loop
7173
CancellationTokenSource cancel_token = new CancellationTokenSource();
7274
```
@@ -75,10 +77,10 @@ CancellationTokenSource cancel_token = new CancellationTokenSource();
7577

7678
We'll work outside-in, first defining our `Main` function at a high level, then implementing each behavior it needs. We need `Main` to do several things:
7779

78-
1. Initialize the AuthToken module, which loads and stores our authentication token to/from local storage.
79-
2. Create the SpacetimeDBClient instance.
80+
1. Initialize the `AuthToken` module, which loads and stores our authentication token to/from local storage.
81+
2. Create the `SpacetimeDBClient` instance.
8082
3. Register callbacks on any events we want to handle. These will print to standard output messages received from the database and updates about users' names and online statuses.
81-
4. Start our processing thread, which connects to the SpacetimeDB module, updates the SpacetimeDB client and processes commands that come in from the input loop running in the main thread.
83+
4. Start our processing thread which connects to the SpacetimeDB module, updates the SpacetimeDB client and processes commands that come in from the input loop running in the main thread.
8284
5. Start the input loop, which reads commands from standard input and sends them to the processing thread.
8385
6. When the input loop exits, stop the processing thread and wait for it to exit.
8486

@@ -154,7 +156,7 @@ string UserNameOrIdentity(User user) => user.Name ?? user.Identity.ToString()!.S
154156

155157
void User_OnInsert(User insertedValue, ReducerEvent? dbEvent)
156158
{
157-
if(insertedValue.Online)
159+
if (insertedValue.Online)
158160
{
159161
Console.WriteLine($"{UserNameOrIdentity(insertedValue)} is online");
160162
}
@@ -178,20 +180,21 @@ We'll print an appropriate message in each of these cases.
178180
```csharp
179181
void User_OnUpdate(User oldValue, User newValue, ReducerEvent dbEvent)
180182
{
181-
if(oldValue.Name != newValue.Name)
183+
if (oldValue.Name != newValue.Name)
182184
{
183185
Console.WriteLine($"{UserNameOrIdentity(oldValue)} renamed to {newValue.Name}");
184186
}
185-
if(oldValue.Online != newValue.Online)
187+
188+
if (oldValue.Online == newValue.Online)
189+
return;
190+
191+
if (newValue.Online)
186192
{
187-
if(newValue.Online)
188-
{
189-
Console.WriteLine($"{UserNameOrIdentity(newValue)} connected.");
190-
}
191-
else
192-
{
193-
Console.WriteLine($"{UserNameOrIdentity(newValue)} disconnected.");
194-
}
193+
Console.WriteLine($"{UserNameOrIdentity(newValue)} connected.");
194+
}
195+
else
196+
{
197+
Console.WriteLine($"{UserNameOrIdentity(newValue)} disconnected.");
195198
}
196199
}
197200
```
@@ -209,7 +212,7 @@ void PrintMessage(Message message)
209212
{
210213
var sender = User.FilterByIdentity(message.Sender);
211214
var senderName = "unknown";
212-
if(sender != null)
215+
if (sender != null)
213216
{
214217
senderName = UserNameOrIdentity(sender);
215218
}
@@ -219,7 +222,7 @@ void PrintMessage(Message message)
219222

220223
void Message_OnInsert(Message insertedValue, ReducerEvent? dbEvent)
221224
{
222-
if(dbEvent != null)
225+
if (dbEvent != null)
223226
{
224227
PrintMessage(insertedValue);
225228
}
@@ -254,7 +257,11 @@ We'll test both that our identity matches the sender and that the status is `Fai
254257
```csharp
255258
void Reducer_OnSetNameEvent(ReducerEvent reducerEvent, string name)
256259
{
257-
if(reducerEvent.Identity == local_identity && reducerEvent.Status == ClientApi.Event.Types.Status.Failed)
260+
bool localIdentityFailedToChangeName =
261+
reducerEvent.Identity == local_identity &&
262+
reducerEvent.Status == ClientApi.Event.Types.Status.Failed;
263+
264+
if (localIdentityFailedToChangeName)
258265
{
259266
Console.Write($"Failed to change name to {name}");
260267
}
@@ -268,7 +275,11 @@ We handle warnings on rejected messages the same way as rejected names, though t
268275
```csharp
269276
void Reducer_OnSendMessageEvent(ReducerEvent reducerEvent, string text)
270277
{
271-
if (reducerEvent.Identity == local_identity && reducerEvent.Status == ClientApi.Event.Types.Status.Failed)
278+
bool localIdentityFailedToSendMessage =
279+
reducerEvent.Identity == local_identity &&
280+
reducerEvent.Status == ClientApi.Event.Types.Status.Failed;
281+
282+
if (localIdentityFailedToSendMessage)
272283
{
273284
Console.Write($"Failed to send message {text}");
274285
}
@@ -282,7 +293,10 @@ Once we are connected, we can send our subscription to the SpacetimeDB module. S
282293
```csharp
283294
void OnConnect()
284295
{
285-
SpacetimeDBClient.instance.Subscribe(new List<string> { "SELECT * FROM User", "SELECT * FROM Message" });
296+
SpacetimeDBClient.instance.Subscribe(new List<string>
297+
{
298+
"SELECT * FROM User", "SELECT * FROM Message"
299+
});
286300
}
287301
```
288302

@@ -370,12 +384,12 @@ void InputLoop()
370384
while (true)
371385
{
372386
var input = Console.ReadLine();
373-
if(input == null)
387+
if (input == null)
374388
{
375389
break;
376390
}
377391

378-
if(input.StartsWith("/name "))
392+
if (input.StartsWith("/name "))
379393
{
380394
input_queue.Enqueue(("name", input.Substring(6)));
381395
continue;
@@ -421,4 +435,4 @@ dotnet run --project client
421435

422436
## What's next?
423437

424-
Congratulations! You've built a simple chat app using SpacetimeDB. You can look at the C# SDK Reference for more information about the client SDK. If you are interested in developing in the Unity3d game engine, check out our Unity3d Comprehensive Tutorial and BitcraftMini game example.
438+
Congratulations! You've built a simple chat app using SpacetimeDB. You can look at the C# SDK Reference for more information about the client SDK. If you are interested in developing in the Unity game engine, check out our Unity3d Comprehensive Tutorial and BitcraftMini game example.

0 commit comments

Comments
 (0)