Nhowka / Elmish.Bridge

Create client-server Fable-Elmish apps keeping a single mindset
MIT License
138 stars 17 forks source link

How to migrage from Cmd.ofSub to Cmd.ofEffect? #59

Closed object closed 4 months ago

object commented 4 months ago

I am upgrading Elmish.Bridge.Client package from 6x to 7x and can't figure out how to update the following code:

let bridgeSubscription (state: State) =
    Bridge.endpoint state.AppSettings.SocketUrl
    |> Bridge.withUrlMode Raw
    |> Bridge.withMapping (fun x -> x |> MediaSetEvent)
    |> Bridge.asSubscription

Program.mkProgram init update view
|> Program.withSubscription (bridgeSubscription >> Cmd.ofSub)
|> Program.withReactSynchronous "elmish-app"
|> Program.withDebugger
|> Program.run

It works fine with Elmish.Bridge.Client prior to version 7, but version 7 replaced ofSub with ofEffect, so this code no longer compiles. But I can't just replace Cmd.ofSub with Cmd.ofEffect because they have different messages and compiler fails with the following error:

Type mismatch. Expecting a '((Messages.Msg -> unit) -> unit) -> Sub'
but given a 'Effect -> Cmd'
The type 'SubId * Subscribe' does not match the type 'Effect'F# Compiler1 val ofEffect: effect: Effect<'msg> -> Cmd<'msg>

Can you point me to a code example that works with the newer syntax? Thanks.

object commented 4 months ago

The problem was not in ofEffect method but in asSubscription that needed update to match Elmish v4. I created a PR for this. Closing this issue.