I have this code I'm running using Fable Elmish and Fable remoting to connect to a Suave server. I know that the server works because of postman and there are variations of this code that does call the server
let AuthUser model : Cmd<LogInMsg> =
let callServer = async {
let! result = server.RequestLogIn model.Credentials
return result
}
let result = callServer |> Async.RunSynchronously
match result with
| LogInFailed x -> Cmd.ofMsg (LogInMsg.LogInRejected x)
| UserLoggedIn x -> Cmd.ofMsg (LogInMsg.LogInSuccess x)
The callServer
line in the let result fails with Object(...) is not a function
, but I don't understand why. Any help would be appreciated.
According to Fable docs Async.RunSynchronously
is not supported, though I'm not sure if that is causing your problem. Anyway you should structure your code so that you don't need to block asynchronous computations. In case of Elmish you can use Cmd.ofAsync
to create a command out of an async that dispatches messages returned by the async when it completes.
let AuthUser model : Cmd<LogInMsg> =
let ofSuccess result =
match result with
| LogInFailed x -> LogInMsg.LogInRejected x
| UserLoggedIn x -> LogInMsg.LogInSuccess x
let ofError exn = (* Message representing failed HTTP request *)
Cmd.ofAsync server.RequestLogIn model.Credentials ofSuccess ofError
Hopefully this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With