Created
August 31, 2015 21:01
-
-
Save amitaibu/4ec789ed57d52cf1d0ac to your computer and use it in GitHub Desktop.
This file contains hidden or 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 EventLog where | |
import Html exposing (..) | |
import Html.Events exposing (..) | |
import Html.Attributes exposing (..) | |
import Signal exposing (..) | |
import StartApp.Simple exposing (..) | |
type alias Model = | |
{ events: List String } | |
initialModel : Model | |
initialModel = | |
{ events = [] } | |
type Action = Mark String | |
| Reset | |
update : Action -> Model -> Model | |
update action log = | |
case action of | |
Mark date -> | |
{ log | events <- log.events ++ [date] } | |
Reset -> | |
{ log | events <- [] } | |
view : Address Action -> Model -> Html | |
view address model = | |
div [] | |
[ button [ onClick address (Mark "?") ] [ text "Mark" ], | |
button [ onClick address Reset ] [ text "Reset" ], | |
h2 [] [ text (model.events |> List.length |> toString), text " Events" ], | |
div [] (List.map (\t -> text t) model.events) | |
] | |
main : Signal Html | |
main = | |
StartApp.Simple.start | |
{ model = initialModel, | |
view = view, | |
update = update } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@kouphax thanks for your nice post!
It seems that
StartApp.Simple
is now needed instead ofStartApp
, so here's the updated code ^^ :)