9

I am trying to understand the difference between mkSimple and mkProgram in Fable-Elmish, or Elmish.WPF which I am actually using. (Can someone perhaps produce a tag for elmish.wpf please?)

I have found Elmish.WPF to be incredibly effective, I use it in production, but I'm at a stage where I'm still learning a lot every day. This particular question is gobbling up too much of my research time, so I would appreciate some help.

The comments in the source looks like this.

mkSimple : Simple program that produces only new state with 'init' and 'update'.

mkProgram : Typical program, new commands are produced by 'init' and 'update' along with the new state.

So what are those commands good for? I have looked at examples in several places, but they don't give much of a clue whether I can do the same with mkSimple as with mkProgram, and that's what I need to know.

Does mkProgram expose some functionality that mkSimple does not, or can everything be done whichever one I use? Is mkSimple only for simple demo use, and should I be using mkProgram for real world applications that grow? If you can do everything with both, then why the difference?

glennsl
  • 28,186
  • 12
  • 57
  • 75
Bent Tranberg
  • 3,445
  • 26
  • 35

1 Answers1

8

mkSimple is really only for learning purposes. It helps ease new users into the framework by not introducing the ideas of Cmd yet.

If you look at the source of mkSimple, you will see that all it is doing is hiding the Cmd idea (by using Cmd.none) and calling mkProgram:

/// Simple program that produces only new state with `init` and `update`.
let mkSimple 
    (init : 'arg -> 'model) 
    (update : 'msg -> 'model -> 'model)
    (view : 'model -> Dispatch<'msg> -> 'view) =
    { init = init >> fun state -> state,Cmd.none
      update = fun msg -> update msg >> fun state -> state,Cmd.none
      view = view
      setState = fun model -> view model >> ignore
      subscribe = fun _ -> Cmd.none
      onError = onError }

Its origins are from the Elm Architecture, which has since renamed the simple program to beginnerProgram.

If you want to want to write a program with any complexity, use mkProgram. If you are merely tinkering or demonstrating the basics, you may be able to use mkSimple.

Chad Gilbert
  • 36,115
  • 4
  • 89
  • 97
  • 1
    Thank you very much. I think you have brought me a giant leap forward, since I believe the answer to my next challenges lies in exploiting exactly those commands, and now I'll switch to mkProgram and learn how it all works. – Bent Tranberg Aug 21 '17 at 12:29