Skip to content

Instantly share code, notes, and snippets.

@mrb

mrb/Main.elm

Created Jul 10, 2017
Embed
What would you like to do?
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
You can’t perform that action at this time.