Skip to content

Instantly share code, notes, and snippets.

@nicck
Created May 17, 2017 10:42
Show Gist options
  • Save nicck/3f666755f4c3ca09cbfbb6aa0f24f47b to your computer and use it in GitHub Desktop.
Save nicck/3f666755f4c3ca09cbfbb6aa0f24f47b to your computer and use it in GitHub Desktop.
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 "+" ]
]
module Data exposing (Model)
type alias Model =
{ counter : Int
}
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 ]
@1602
Copy link

1602 commented May 17, 2017

sorry, complete fix is:

diff --git a/Main.elm b/Main.elm
index 9b644a7..cc67985 100644
--- a/Main.elm
+++ b/Main.elm
@@ -12,13 +12,15 @@ main =
 model : Model
 model = { counter = 10 }

-type Msg = Counter.Msg | Int
+type Msg = CounterMsg Counter.Msg | In

 update : Msg -> Model -> Model
 update msg model =
     case msg of
-        Counter.Msg ->
-            Counter.update msg model
+        CounterMsg m ->
+            Counter.update m model
+        In ->
+            model


 view : Model -> Html Msg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment