Created
July 10, 2017 00:38
-
-
Save mrb/b5f87cf3d8918c87ff211d2ed3427d88 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 (..) | |
import Html exposing (..) | |
import TestPanel exposing (..) | |
main = | |
Html.program | |
{ init = init | |
, view = view | |
, update = update | |
, subscriptions = subscriptions | |
} | |
type Panel | |
= TestPanel | |
type alias Model = | |
{ testPanel : TestPanel.Model | |
} | |
init = | |
( Model TestPanel.initModel, Cmd.none ) | |
subscriptions : Model -> Sub Msg | |
subscriptions model = | |
Sub.none | |
-- UPDATE | |
type Msg | |
= TestPanelMsg TestPanel.Msg | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
TestPanelMsg msg -> | |
let | |
( m, c ) = | |
TestPanel.update msg model.testPanel | |
in | |
( { model | testPanel = m }, Cmd.map TestPanelMsg c ) | |
-- VIEW | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ TestPanel.view model.testPanel |> Html.map TestPanelMsg | |
] |
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 TestPanel exposing (..) | |
import Html exposing (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
type alias Model = | |
{ state : Int | |
, state2 : Int | |
} | |
initModel = | |
Model 0 0 | |
-- UPDATE | |
type Msg | |
= SetState Int | |
| SetState2 Int | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
SetState i -> | |
( { model | state = i }, Cmd.none ) | |
SetState2 i -> | |
( { model | state2 = i }, Cmd.none ) | |
-- VIEW | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ model.state |> toString |> text | |
, br [] [] | |
, model.state2 |> toString |> text | |
, br [] [] | |
, Html.a [ onClick (SetState (model.state + 1)) ] [ text "+" ] | |
, br [] [] | |
, br [] [] | |
, Html.a [ onClick (SetState2 (model.state2 + 1)) ] [ text "+" ] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment