Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elm effects, the tick function apparently never get called

Tags:

elm

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.

like image 209
fayong lin Avatar asked Feb 07 '23 21:02

fayong lin


1 Answers

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
like image 125
Chad Gilbert Avatar answered Mar 23 '23 00:03

Chad Gilbert