Skip to content

Commit 6865e3f

Browse files
authored
Merge pull request #309 from WhiteOlivierus/fix/documentation
Add some missing essential information to the documentation
2 parents 7cc1d43 + 7aa6069 commit 6865e3f

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ TypedSignalR.Client.TypeScript is a library/CLI tool that analyzes SignalR hub a
2222
- [Recommended Configuration](#recommended-configuration)
2323
- [Related Work](#related-work)
2424

25-
2625
## Why TypedSignalR.Client.TypeScript?
2726

2827
Implementing SignalR Hubs (server-side) in C# can be strongly typed by using interfaces, but the [TypeScript SignalR client](https://github.com/dotnet/aspnetcore/tree/main/src/SignalR/clients/ts/signalr) is not strongly typed. To call Hub methods, we must specify the method defined in Hub using a string. We also have to determine the return type manually. Moreover, registering client methods called from a server also requires specifying the method name as a string, and we must set parameter types manually.
@@ -82,7 +81,7 @@ export type ReceiverRegisterProvider = {
8281
(receiverType: "IReceiver2"): ReceiverRegister<IReceiver2>;
8382
}
8483

85-
export const getHubProxyFactory : HubProxyFactoryProvider = ...;
84+
export const getHubProxyFactory : HubProxyFactoryProvider = ...;
8685
export const getReceiverRegister : ReceiverRegisterProvider = ...;
8786
```
8887

@@ -149,6 +148,8 @@ Then, annotate `HubAttribute` and `ReceiverAttribute` to each interface definiti
149148
Also, annotate `TranspilationSourceAttribute` to user-defined types used in the interface definition of Hub and Receiver.
150149
Adding this attribute is relatively easy if you add the [TypedSignalR.Client.TypeScript.Analyzer](#analyzer) to your project.
151150

151+
> Make sure that all your hubs, receivers and models are within a namespace, otherwise the generator will not work.
152+
152153
```cs
153154
using Tapper;
154155
using TypedSignalR.Client;
@@ -180,7 +181,15 @@ Finally, enter the following command.
180181
This command analyzes C# and generates TypeScript code.
181182

182183
```bash
183-
$ dotnet tsrts --project path/to/Project.csproj --output generated
184+
$ dotnet tsrts --project path/to/Project.csproj --output generated --asm true
185+
```
186+
187+
Or add it to your build steps in your csproj.
188+
189+
```xml
190+
<Target Name="SignalRClient" AfterTargets="PostBuildEvent" Condition=" '$(Configuration)'!='Release'">
191+
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tsrts --project path/to/Project.csproj --output generated --asm true" ContinueOnError="WarnAndContinue" />
192+
</Target>
184193
```
185194

186195
The generated code can be used as follows.
@@ -224,7 +233,6 @@ const participants = await hubProxy.getParticipants()
224233
// ...
225234
```
226235

227-
228236
## Supported Types
229237

230238
TypedSignalR.Client.TypeScript uses a library named [nenoNaninu/Tapper](https://github.com/nenoNaninu/Tapper) to convert C# types to TypeScript types.
@@ -266,12 +274,12 @@ public record CustomType2(float Value, DateTime ReleaseDate);
266274
```
267275

268276
## Analyzer
277+
269278
User-defined types used in parameters and return values of methods defined within interfaces annotated with `Hub` or `Receiver` must be annotated with `TranspilationSource`.
270279
The Analyzer checks in real-time whether this rule is followed. If not, the IDE will tell you.
271280

272281
![analyzer](https://user-images.githubusercontent.com/27144255/170770137-28790bcf-08d1-403f-9625-2cdf6f390e76.gif)
273282

274-
275283
## Streaming Support
276284

277285
SignalR supports both [server-to-client streaming and client-to-server streaming](https://docs.microsoft.com/en-us/aspnet/core/signalr/streaming?view=aspnetcore-6.0).
@@ -349,7 +357,7 @@ If you use `Task<T>` for the method return type in the receiver interface, you c
349357
[Receiver]
350358
public interface IMyHubReceiver
351359
{
352-
// Return type: Task<T>
360+
// Return type: Task<T>
353361
Task<Guid> GetGuidFromClient();
354362
}
355363
```
@@ -422,6 +430,7 @@ $ dotnet tsrts --project path/to/Project.csproj --output generated --serializer
422430
```
423431

424432
## Related Work
433+
425434
- [nenoNaninu/TypedSignalR.Client](https://github.com/nenoNaninu/TypedSignalR.Client)
426435
- C# Source Generator to create strongly typed SignalR clients.
427436
- [nenoNaninu/TypedSignalR.Client.DevTools](https://github.com/nenoNaninu/TypedSignalR.Client.DevTools)

0 commit comments

Comments
 (0)