For those interested: here is the example I refered to:
import Html exposing (..)
import Html.Events exposing (onClick)
import Time exposing (Time, second)
import Task
main =
Html.program
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
-- MODEL
type alias Model = { msgs : List String, timerOn : Bool }
init : (Model, Cmd Msg)
init =
{ msgs = []
, timerOn = True
} ! []
-- UPDATE
type Msg
= Tick Time | DoStuff | DoMore
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
Tick newTime ->
{ msgs = toString msg :: model.msgs
, timerOn = True
} ! []
DoStuff ->
{ model | msgs = toString msg :: model.msgs }
! [ send DoMore ]
DoMore ->
{ model | msgs = toString msg :: model.msgs, timerOn = False } ! []
send : msg -> Cmd msg
send msg =
Task.succeed msg
|> Task.perform identity
-- SUBSCRIPTIONS
subscriptions : Model -> Sub Msg
subscriptions model =
if model.timerOn then
Time.every 10 Tick
else
Sub.none
-- VIEW
view : Model -> Html Msg
view model =
div []
[ button [ onClick DoStuff ] [ text "click" ]
, ul []
<| List.map itemView model.msgs
]
itemView : String -> Html Msg
itemView string =
li [] [ text string ]
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.