How to send a message to the Dispatcher from a custom event in Elmish.wpf/Elmish?

74 Views Asked by At

In F#, I have a custom event as a singleton:

type EventMediator private () =
    let mutable _name = "";

    static member val private _instance = lazy EventMediator()
    static member Instance = EventMediator._instance.Value

    member val private nameChanged = Event<unit>()
    member this.NameChanged = this.nameChanged.Publish

    member this.Name
        with get() = _name
        and set(value) =
            _name <- value
            this.nameChanged.Trigger()

Once triggered, it is received in a separate module as:

let p = EventMediator.Instance
p.NameChanged.Add(fun () -> dispatch RequestAppointmentsMsg )  <--WRONG!

where RequestAppointmentsMsg is defined (Elemish.wpf) as

type Msg =    
    | RequestAppointmentsMsg 

The call-back to the event is outside of the Update loop.

How can I send the message "RequestAppointmentsMsg" in Elmish.wpf/Elmish to the dispatcher so it will be acted upon by the Update loop?

TIA

Note: the signature for the update loop is:

 update (msg:Msg) (m:Registration) : Registration * Cmd<Msg> = ....
0

There are 0 best solutions below