Created
October 21, 2018 17:48
-
-
Save Chadtech/63d2dec2960a394e902693a43c8d17e8 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 Main exposing (main) | |
import Browser | |
import Html exposing (Html, button, div, text) | |
import Html.Events exposing (onClick) | |
import Component | |
type alias Model = | |
{ count : Int | |
, component : Component.Model | |
} | |
initialModel : Model | |
initialModel = | |
{ count = 0 | |
, component = Component.init | |
} | |
type Msg | |
= Increment | |
| Decrement | |
| ComponentMsg Component.Msg | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
Increment -> | |
{ model | count = model.count + 1 } | |
Decrement -> | |
{ model | count = model.count - 1 } | |
ComponentMsg subMsg -> | |
let | |
newComponentModel = | |
Component.update subMsg model.component | |
in | |
{ model | |
| component = newComponentModel | |
} | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ button [ onClick Increment ] [ text "+1" ] | |
, div [] [ text <| String.fromInt model.count ] | |
, button [ onClick Decrement ] [ text "-1" ] | |
, Html.map ComponentMsg (Component.view model.component) | |
] | |
main : Program () Model Msg | |
main = | |
Browser.sandbox | |
{ init = initialModel | |
, view = view | |
, update = update | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment