[WIP] Adding Elmish.Bridge as a communication option#265
[WIP] Adding Elmish.Bridge as a communication option#265Nhowka wants to merge 6 commits intoSAFE-Stack:masterfrom
Conversation
|
First thing - big thanks for that, adding a feature like that is quite a challenge and I really appreciate your work on that since I realise what was involved. Regarding the changes: can we just send the initial counter via Elmish.Bridge instead of introducing the clock? Also on a different note: those changes are quite big, and TBH I have never used Elmish.Bridge before. |
|
All in all it looks really good! One thing I noticed is executing side-effects inside event handlers, i.e. calling |
We could, but it's not really suitable for actions that are just one-time things as it creates a stateful connection between the server and client. Instead I could make the counter server-side and the client would just show the counter that would be incremented/decremented on the server, but that would make it harder to add a new endpoint to the api or be compatible with the remoting option as it would not have a starting point for them. Let me know if you are ok with the drawbacks.
Yes, I'm willing to work on it and to smooth any rough edges that may appear.
After making excuses for my laziness while replying I thought of a smarter way to fix that without much work. I'll test it and apply the changes if it works. |
It shouldn't require a lot of work to create a command from the module Cmd =
let bridgeSend (msg 't) : Cmd<'t> = [ fun _ -> Bridge.Send msg |> ignore ]There might an existing |
|
I might've just changed one problem for another. My idea was creating a new case on the messages, something like I'll investigate if the |
Yeah then you need to
Yeah definitely! This is a suggestion for the library (maybe not the best place to discuss it here but) the module Cmd =
let inline bridgeSend (msg: 'Msg) (onError: exn -> 'Msg) =
[ fun dispatch -> Bridge.SendSafe msg (fun error -> dispatch (onError error) ]where The example above only communicates the errors back to the dispatch loop but you could have other callbacks that tell the success status etc. Let me know what you think |
I works! ❤
Maybe making a happy one that will gladly ignore the unsent messages when the socket is down and another that will try to add something to the loop. Adding an optional module Cmd =
let inline bridgeSend (msg:'server) : Cmd<'client> = [ fun _ -> Bridge.Send msg ]
let inline bridgeSendOr (msg:'server) (fallback:'client) : Cmd<'client> = [ fun dispatch -> Bridge.Send(msg, fun () -> dispatch fallback) ]That is assuming that the message only fails to be sent when the socket closes. That would support different recoveries as different messages are tried to be sent when the socket is not up, but there is already an option to send a message when the socket closes. |
|
@Nhowka how about sending the clock from server, but use it for |
|
Can we close this as #267 went in? |
|
Yes, thanks! |
Implementing #107
I tried to modify as little as possible, only adding a simple clock that can be paused so the tick won't be sent to the client. Now probably need some more comments so the user can know better where to modify.
Sending the PR as the CI is very nice on checking if I broke anything.
cc @theimowski @isaacabraham @Zaid-Ajaj