2

(Newbie question).

In Elmish.WPF, I have a parent module, App, holding a child submodule, FinderLastName:

module App =

    type Model =
        { 
            FinderLastName:  FinderLastName.Model      
        }

    type Msg =
        | FinderLastNameMsg  of FinderLastName.Msg
       

    let update msg m =
        match msg with
        | FinderLastNameMsg msg ->
            { m with FinderLastName  = FinderLastName.update msg m.FinderLastName}
       
    let bindings () : Binding<Model, Msg> list = [
        "FinderLastName" |> Binding.subModel(
          (fun m -> m.FinderLastName),
          snd,
          FinderLastNameMsg,
          FinderLastName.bindings)
     ]

The subModel, FinderLastName , receives a text input from the UI which I need to transmit up to the main App module.

Assuming the subModel, FinderLastName, has the typical Elmish.WPF structure of Model, Msg, and update, how do I transmit the text input from child/subModel to parent/main Model?

(I found a good discussion of this for Elm-spa, but how would this be used in Elmish.WPF? https://discourse.elm-lang.org/t/modifying-parent-state-from-child-page-in-an-elm-spa-example-like-architecture/2437)

Any ideas would be most appreciated.

TIA

Found it! Please see the really good blog at: https://medium.com/@MangelMaxime/my-tips-for-working-with-elmish-ab8d193d52fd

About 3/4 of the way down, Make the child communicate with the parent

Addendum: For a good explanation of the event loops used by Elmish, see: https://elmish.github.io/elmish/

Alan Wayne
  • 5,122
  • 10
  • 52
  • 95
  • OP and I are having a similar discussion in [this issue (starting with the quote in that comment)](https://github.com/elmish/Elmish.WPF/issues/300#issuecomment-732129515). – Tyson Williams Nov 26 '20 at 02:04

2 Answers2

3

OP shared this Elm discussion in this comment. As I said in this comment, I like the translator pattern that was mentioned there. I plan on implementing it in Elmish.WPF soon.

Tyson Williams
  • 1,630
  • 15
  • 35
2

The Elmish.WPF repo has several good sample projects built in which demonstrate this sort of thing. Look at the projects with "SubModel" in the name.

I suggest you clone the repo and open it in your IDE to get full type inference. You can also run each sample project. I personally think this is a really good form of documentation.

TheQuickBrownFox
  • 10,544
  • 1
  • 22
  • 35
  • I've been studying that code. I don't see where it sends any information back to the top model. It appears each submodel handles itself?? Thanks. – Alan Wayne Nov 25 '20 at 17:38
  • One of the Elmish.WPF maintainers here. @AlanWayne is correct. None of the samples involve child-to-parent communication. – Tyson Williams Nov 26 '20 at 02:01
  • @AlanWayne Ah I was really just hoping it would contain your answer but I will leave this here because I don't think it's obvious to everyone that the samples in the repo are an excellent resource. – TheQuickBrownFox Nov 26 '20 at 11:34