Created
May 17, 2017 10:42
-
-
Save nicck/3f666755f4c3ca09cbfbb6aa0f24f47b 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 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 characters
| 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 characters
| 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 ] |
Author
nicck
commented
May 17, 2017
update : Msg -> Model -> Model
update msg model =
case msg of
Counter.Msg counterMsg ->
Counter.update counterMsg modelsorry, 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