Skip to content

How to send a message to the Dispatcher from a custom event? #572

@awaynemd

Description

@awaynemd

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 = "";

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?

Thank you.

Note: the signature for the update loop is:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions