Created
August 1, 2016 20:39
-
-
Save sectore/be2700e0b0b071878695d42baeb238b3 to your computer and use it in GitHub Desktop.
How to run `Time.now` with `init`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main exposing (..) | |
import Html exposing (..) | |
import Html.App as Html | |
import Time | |
import Basics.Extra exposing (never) | |
import Task | |
main : Program Never | |
main = | |
Html.program | |
{ init = init | |
, view = view | |
, update = update | |
, subscriptions = subscriptions | |
} | |
-- MODEL | |
type alias Model = | |
{ now : Time.Time } | |
init : ( Model, Cmd Msg ) | |
init = | |
( Model 0, Task.perform never TrackTime Time.now ) | |
-- UPDATE | |
type Msg | |
= TrackTime Time.Time | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
TrackTime time -> | |
( { model | now = time }, Cmd.none ) | |
-- SUBSCRIPTIONS | |
subscriptions : Model -> Sub Msg | |
subscriptions model = | |
Sub.none | |
-- VIEW | |
view : Model -> Html Msg | |
view model = | |
h1 [] [ text <| " now: " ++ toString model.now ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment