Skip to content

Instantly share code, notes, and snippets.

@havarnov
Created October 13, 2016 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havarnov/cec552304ee6d9e4af58e617b0f87ace to your computer and use it in GitHub Desktop.
Save havarnov/cec552304ee6d9e4af58e617b0f87ace to your computer and use it in GitHub Desktop.
import Html exposing (..)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Json.Decode as Json exposing ((:=))
import Mouse exposing (Position)
main =
App.program
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
-- MODEL
type alias Model =
{ state: Maybe (List Int)
}
init : (Model, Cmd Msg)
init =
( { state = Nothing }, Cmd.none )
-- UPDATE
type Msg
= Inc
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Inc ->
case model.state of
Just l ->
let
x = Maybe.withDefault 1 (Maybe.map (\i -> i+1) (List.head l))
l = (x::l)
in
( { model | state = Just l }, Cmd.none)
Nothing ->
( { model | state = Just [1]}, Cmd.none)
-- SUBSCRIPTIONS
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none
-- VIEW
view : Model -> Html Msg
view model =
div []
[ text (toString model.state)
, button [onClick Inc] [text "yo"]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment