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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With