只需处理样本,就可以创建2个随机骰子并用按钮滚动它们.
http://guide.elm-lang.org/architecture/effects/random.html
所以我想我会将骰子创建为模块,删除滚动动作,然后让它在init上创建D6值.
所以我的代码现在如下(应该直接在elm-reactor中打开)
module Components.DiceRoller exposing (Model, Msg, init, update, view)
import Html exposing (..)
import Html.App as Html
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Random
import String exposing (..)
main =
Html.program
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
-- MODEL
type alias Model =
{ dieFace : Int
}
init : ( Model, Cmd Msg )
init =
( Model 0, (Random.generate NewFace (Random.int …Run Code Online (Sandbox Code Playgroud)