榆木效果,壁虱函数显然永远不会被调用 [英] elm effects, the tick function apparently never get called
问题描述
我试图使我的模型对时钟滴答做出反应,以便进行一些动画,如榆木建筑教程的示例8(旋转立方体)。
I am trying to make my model react to the clock ticks in order to do some animation like the example 8 (spinning cube) of the elm architecture tutorial.
https://github.com/evancz/elm-architecture-tutorial
由于我的程序无法正常运行,所以我尝试举一个最简单的例子来说明我的问题。
Since my program is not working I tried to make the simplest example I could demonstrating my problem.
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
当我运行该按钮时,当我单击该按钮时,该模型已正确更新为已启动,但从未触发滴答操作。
when I run this the model is correctly updated to "started" when I click the button, but the Tick action is never triggered.
我可能在这里丢失了一些东西,但我不知道在哪里。
I am probably missing something here but I don't know where.
推荐答案
您缺少任务端口。将其添加进去,然后就应该准备好了:
You're missing the tasks port. Add this in and you should be all set:
port tasks : Signal (Task.Task Effects.Never ())
port tasks =
app.tasks
这篇关于榆木效果,壁虱函数显然永远不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!