Created
October 13, 2016 12:16
-
-
Save havarnov/cec552304ee6d9e4af58e617b0f87ace to your computer and use it in GitHub Desktop.
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
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