{"id":13686701,"url":"https://github.com/Shmew/Fable.SignalR","last_synced_at":"2025-05-01T09:32:26.958Z","repository":{"id":45047231,"uuid":"273960622","full_name":"Shmew/Fable.SignalR","owner":"Shmew","description":"A functional type-safe wrapper for SignalR and Fable.","archived":false,"fork":false,"pushed_at":"2024-04-10T11:44:41.000Z","size":2865,"stargazers_count":90,"open_issues_count":10,"forks_count":17,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-06T01:11:12.496Z","etag":null,"topics":["fable","react","signalr","web","websocket"],"latest_commit_sha":null,"homepage":"https://shmew.github.io/Fable.SignalR/","language":"F#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Shmew.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"Contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-21T18:22:06.000Z","updated_at":"2024-11-04T23:45:40.000Z","dependencies_parsed_at":"2024-06-21T12:58:09.966Z","dependency_job_id":"3d8b4405-72a9-43e8-af58-f59d48d41aea","html_url":"https://github.com/Shmew/Fable.SignalR","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shmew%2FFable.SignalR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shmew%2FFable.SignalR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shmew%2FFable.SignalR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shmew%2FFable.SignalR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Shmew","download_url":"https://codeload.github.com/Shmew/Fable.SignalR/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251852891,"owners_count":21654479,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fable","react","signalr","web","websocket"],"created_at":"2024-08-02T15:00:38.155Z","updated_at":"2025-05-01T09:32:26.618Z","avatar_url":"https://github.com/Shmew.png","language":"F#","funding_links":[],"categories":["F# #"],"sub_categories":[],"readme":"# Fable.SignalR [![Nuget](https://img.shields.io/nuget/v/Fable.SignalR.svg?maxAge=0\u0026colorB=brightgreen\u0026label=Fable.SignalR)](https://www.nuget.org/packages/Fable.SignalR)\n\nFable bindings for the SignalR client, a wrapper for the .NET client, \nand ASP.NET Core/Giraffe/Saturn wrappers for SignalR server hubs.\n\nThe full documentation can be found [here](https://shmew.github.io/Fable.SignalR/).\n\n### On the client\n\n```fsharp\nlet textDisplay = React.functionComponent(fun (input: {| count: int; text: string |}) -\u003e\n    React.fragment [\n        Html.div input.count\n        Html.div input.text\n    ])\n\nlet buttons = React.functionComponent(fun (input: {| count: int; hub: Hub\u003cAction,Response\u003e |}) -\u003e\n    React.fragment [\n        Html.button [\n            prop.text \"Increment\"\n            prop.onClick \u003c| fun _ -\u003e input.hub.current.sendNow (Action.IncrementCount input.count)\n        ]\n        Html.button [\n            prop.text \"Decrement\"\n            prop.onClick \u003c| fun _ -\u003e input.hub.current.sendNow (Action.DecrementCount input.count)\n        ]\n        Html.button [\n            prop.text \"Get Random Character\"\n            prop.onClick \u003c| fun _ -\u003e input.hub.current.sendNow Action.RandomCharacter\n        ]\n    ])\n\nlet render = React.functionComponent(fun () -\u003e\n    let count,setCount = React.useState 0\n    let text,setText = React.useState \"\"\n\n    let hub =\n        React.useSignalR\u003cAction,Response\u003e(fun hub -\u003e \n            hub.withUrl(Endpoints.Root)\n                .withAutomaticReconnect()\n                .configureLogging(LogLevel.Debug)\n                .onMessage \u003c|\n                    function\n                    | Response.NewCount i -\u003e setCount i\n                    | Response.RandomCharacter str -\u003e setText str\n        )\n            \n    Html.div [\n        prop.children [\n            textDisplay {| count = count; text = text |}\n            buttons {| count = count; hub = hub |}\n        ]\n    ])\n```\n\n### On the server\n\n```fsharp\nmodule SignalRHub =\n    open FSharp.Control.Tasks.V2\n\n    let update (msg: Action) =\n        match msg with\n        | Action.IncrementCount i -\u003e Response.NewCount(i + 1)\n        | Action.DecrementCount i -\u003e Response.NewCount(i - 1)\n        | Action.RandomCharacter -\u003e\n            let characters = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\"\n            \n            System.Random().Next(0,characters.Length-1)\n            |\u003e fun i -\u003e characters.ToCharArray().[i]\n            |\u003e string\n            |\u003e Response.RandomCharacter\n\n    let invoke (msg: Action) _ =\n        task { return update msg }\n\n    let send (msg: Action) (hubContext: FableHub\u003cAction,Response\u003e) =\n        update msg\n        |\u003e hubContext.Clients.Caller.Send\n\napplication {\n    use_signalr (\n        configure_signalr {\n            endpoint Endpoints.Root\n            send SignalRHub.send\n            invoke SignalRHub.invoke\n        }\n    )\n    ...\n}\n```\n\n### The shared file\n\n```fsharp\n[\u003cRequireQualifiedAccess\u003e]\ntype Action =\n    | IncrementCount of int\n    | DecrementCount of int\n    | RandomCharacter\n\n[\u003cRequireQualifiedAccess\u003e]\ntype Response =\n    | NewCount of int\n    | RandomCharacter of string\n\nmodule Endpoints =\n    let [\u003cLiteral\u003e] Root = \"/SignalR\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShmew%2FFable.SignalR","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FShmew%2FFable.SignalR","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShmew%2FFable.SignalR/lists"}