我试图让我的模型对时钟滴答作出反应,以便像榆树架构教程的示例8(旋转立方体)那样做一些动画。
https://github.com/evancz/elm-architecture-tutorial
由于我的程序无效,我试图制作一个最简单的例子,我可以证明我的问题。
module Test where
import Html exposing (..)
import Html.Events exposing (..)
import StartApp as StartApp
import Effects exposing (..)
import Time exposing (..)
type alias Model =
{debug : String}
type Action =
Start | Tick Time
initialModel = Model "initial"
update : Action -> Model -> (Model, Effects Action)
update action model =
case action of
Start -> ({model | debug = "started"}, Effects.tick Tick)
Tick _ -> ({model | debug = "hasTicked"}, Effects.none)
view : Signal.Address Action -> Model -> Html
view address model =
div []
[ button [onClick address Start] [text "start"]
, p [] [text (.debug model)]
]
app =
StartApp.start
{ init = (initialModel, Effects.none)
, view = view
, update = update
, inputs = []
}
main =
app.html
当我运行此模型时,单击按钮时模型已正确更新为“已启动”,但从未触发Tick操作。
我可能在这里遗漏了一些东西,但我不知道在哪里。
答案 0 :(得分:7)
您错过了任务端口。添加它,您应该全部设置:
port tasks : Signal (Task.Task Effects.Never ())
port tasks =
app.tasks