Created
May 17, 2017 10:42
-
-
Save nicck/3f666755f4c3ca09cbfbb6aa0f24f47b to your computer and use it in GitHub Desktop.
Revisions
-
nicck created this gist
May 17, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ module Counter exposing (view, update, Msg) import Data exposing (Model) import Html exposing (Html, body, div, button, text) import Html.Attributes exposing (attribute, class) -- import Html.Events exposing (onClick) type Msg = Increment Int | Decrement Int update : Msg -> Model -> Model update msg model = case msg of Increment off -> { model | counter = model.counter + off } Decrement off -> { model | counter = model.counter - off } view : String -> Model -> Html msg view label model = div [ class "counter" ] -- [ button [ onClick (Decrement 2) ] [ text "-" ] [ button [ ] [ text "-" ] , div [] [ text (label ++ ": ") , text (toString model.counter) ] -- , button [ onClick (Increment 2) ] [ text "+" ] , button [ ] [ text "+" ] ] 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ module Data exposing (Model) type alias Model = { counter : Int } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ module Main exposing (..) import Html exposing (Html, body, div, button, text) import Html.Attributes exposing (attribute, class) import Counter import Data exposing (Model) main : Program Never Model Msg main = Html.beginnerProgram { model = model, view = view, update = update } model : Model model = { counter = 10 } type Msg = Counter.Msg | Int update : Msg -> Model -> Model update msg model = case msg of Counter.Msg -> Counter.update msg model view : Model -> Html Msg view model = body [ attribute "id" "main" ] [ Counter.view "Counter" model ]