You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Elmish.wpf, 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 to the dispatcher so it will be acted upon by the Update loop?
I take it that it is pretty important that EventMediator be initialized lazily? Otherwise, of course, you could use an F# module instead of hand-writing a static class.
Once triggered, it is received in a separate module
Where is the separate module in your code structure? The means by which you will send RequestAppointmentsMsg to the dispatcher depends on the location of the event handler. If your WPF code handles the event, make an Elmish.WPF command binding in your view model that returns message RequestAppointmentsMsg, then execute the binding's ICommand from your WPF code. If the event handler isn't accessible to your WPF code but is accessible to your main function (step 7 in the README), you can pass the dispatcher into the class constructor as an argument, then use Elmish.Cmd.ofEffect to connect it to the Elmish loop. But this method is significantly more complicated, so I would need more information to walk you through it.
This is a repost of a StackOverflow question.
In Elmish.wpf, I have a custom event as a singleton:
type EventMediator private () =
let mutable _name = "";
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 to the dispatcher so it will be acted upon by the Update loop?
Thank you.
Note: the signature for the update loop is:
update (msg:Msg) (m:Registration) : Registration * Cmd = ....
The text was updated successfully, but these errors were encountered: