Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vforteli/dotnet-typescript-hub-generator
TypeScript client generator for SignalR Hubs
https://github.com/vforteli/dotnet-typescript-hub-generator
Last synced: about 13 hours ago
JSON representation
TypeScript client generator for SignalR Hubs
- Host: GitHub
- URL: https://github.com/vforteli/dotnet-typescript-hub-generator
- Owner: vforteli
- Created: 2024-11-10T17:20:16.000Z (8 days ago)
- Default Branch: main
- Last Pushed: 2024-11-10T20:42:44.000Z (8 days ago)
- Last Synced: 2024-11-10T21:19:28.220Z (8 days ago)
- Language: C#
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TypeScriptHubGenerator
Create TypeScript clients from SignalR hubs.
For React, a context and hook is created.
# Using the tool
```
# install globally (or locally)
dotnet tool install --global vforteli.TypeScriptHubGenerator# run the tool
dotnet tshubgen \
--generate \
--assembly-path "some/folder/assembly.dll" \
--output-folder "some/other/folder" \
--create-react-context
```# Using the client
## React
Using the client requires installing @microsoft/signalr (tested with version 8.0.7)
```typescript jsx
// Configure hub in eg App.tsx
function App() {
const hubConnection = new HubConnectionBuilder()
.withAutomaticReconnect()
.withUrl("someurl")
.build();return (
<>...>
);
}
``````typescript jsx
// Use in some component
export const SomeComponent = () => {
const someHub = useSomeHubClient();const handleSomethingHappened = useCallback((message: string | null) => {
console.debug("hub: " + message);
}, []);useEffect(() => {
someHub.hub.addSomethingHappenedHandler(handleSomethingHappened);return () => {
someHub.hub.removeSomethingHappenedHandler(handleSomethingHappened);
};
}, [handleSomethingHappened, someHub.hub]);return <>...>;
};
```