0

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> = ....
Alan Wayne
  • 5,122
  • 10
  • 52
  • 95
  • 2
    You use the dispatcher to send a message. Look at the FileDialogs example in the Elmish.WPF repo. In addition to the WpfProgram.withSubscription (or equivalent in other Elmish implementations), you can also use Cmd.ofSub (fun dispatcher -> typically from a model's init function to instantiate an object that you can hand the dispatcher to, for later calls. – Bent Tranberg Jun 24 '23 at 18:21
  • 1
    Do not simultaneously cross post: https://github.com/elmish/Elmish.WPF/issues/572 – Tyson Williams Jun 25 '23 at 11:37

0 Answers0