What is the correct way of initializing an elm application

后端 未结 4 1010
有刺的猬
有刺的猬 2020-12-31 02:46

The documentation for Elm\'s Random module states:

A good way to get an unexpected seed is to use the current time. http://package.elm-

4条回答
  •  隐瞒了意图╮
    2020-12-31 03:35

    Just an update for people who got here from Google like I did: the recommended way to do this now is with flags instead of ports. The code in the other answers will not even compile now.

    https://guide.elm-lang.org/interop/javascript.html

    HTML

    
    

    Elm

    type alias Model = {
      mySeed : String
    }
    
    type alias Flags = {
      myRandomValue : String
    }
    
    init : Flags -> ( Model, Cmd Msg )
    init flags =
      {
        mySeed = flags.myRandomValue
      }
    

    ...

    main : Program Flags Model Msg
    main = programWithFlags
      {
        view = view,
        init = init,
        update = update
      }
    

提交回复
热议问题