Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does mkProgram expose more functionality than mkSimple?

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?

like image 439
Bent Tranberg Avatar asked Aug 21 '17 11:08

Bent Tranberg


1 Answers

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.

like image 161
Chad Gilbert Avatar answered Nov 16 '22 01:11

Chad Gilbert