This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Like evancz/start-app, but with `update : action -> Time -> model -> model`.
version 1.0.1
license BSD3
native-modules False
elm-version 0.15.0 <= v < 0.17.0
Tag 1.0.1
Committed At 2016-02-16 02:54:59 UTC
evancz/elm-html 3.0.0 <= v < 5.0.0 4.0.2
evancz/elm-effects 2.0.0 <= v < 3.0.0 2.0.1
elm-lang/core 2.0.1 <= v < 4.0.0 3.0.0

README

What is this?

This is a fork of Evan Czaplicki's StartApp for Elm.

If you are here, you should first understand how StartApp works. Read up.

If you want to know why this exists, read this.

OK, now that you've read that and are an expert at StartApp, know that:
StartApp has been renamed to TimeApp and StartApp.Simple has been renamed to TimeApp.Simple.

The important change is TimeApp.Simple's update has signature:

update : action -> Time -> model -> model

As opposed to StartApp.Simple's update signature of:

update : action -> model -> model

That simply means your update function receives Time as an argument so you know at what time update was called. This is nice because in a pure functional language you can't just "ask for the current time".

TimeApp has been similarly modified so as to have:

update : action -> Time -> model -> (model, Effects action)

as opposed to StartApp's:

update : action -> model -> (model, Effects action)

Example


import Html exposing (div, button, text)
import Html.Events exposing (onClick)
import TimeApp.Simple as TimeApp
import StartTime
import Time exposing (Time)

main =
  TimeApp.start { model = model, view = view, update = update }

model : {count : Int, prevEventTime : Maybe Time, eventTime : Maybe Time}
model =
  { count = 0
  , prevEventTime = Nothing
  , eventTime = Nothing
  }

view address model =
  let
    timeBetweenUpdatesMessage =
      case (model.prevEventTime, model.eventTime) of
        (Just prevTime, Just time) ->
          ((time - prevTime ) / 1000.0 |> toString) ++ " seconds between updates."
        _ -> ""
  in
    div []
      [ button [ onClick address Decrement ] [ text "-" ]
      , div [] [ text <| (toString model.count)]
      , div [] [ text <| timeBetweenUpdatesMessage ]
      , button [ onClick address Increment ] [ text "+" ]
      , div [] [ ]
      ]

type Action = Increment | Decrement

update action time model =
  case action of
    Increment -> {count = model.count + 1, eventTime = Just time, prevEventTime = model.eventTime}
    Decrement -> {count = model.count - 1, eventTime = Just time, prevEventTime = model.eventTime}