Skip to content

Instantly share code, notes, and snippets.

@mrb
Created July 10, 2017 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrb/b5f87cf3d8918c87ff211d2ed3427d88 to your computer and use it in GitHub Desktop.
Save mrb/b5f87cf3d8918c87ff211d2ed3427d88 to your computer and use it in GitHub Desktop.
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
]
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