Created
July 17, 2017 23:16
-
-
Save nqthqn/5843404710c279427203a582a1bef488 to your computer and use it in GitHub Desktop.
message wrapping
This file contains 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 Foo exposing (..) | |
type Msg | |
= Uno | |
| Dos | |
| Tres | |
update msg foo = | |
case msg of | |
Uno -> | |
1 | |
Dos -> | |
2 | |
Tres -> | |
3 |
This file contains 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 Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
import Foo | |
type alias Model = | |
{ foo : Int | |
, bar : Int | |
} | |
type Msg | |
= Bar | |
| FooMsg Foo.Msg | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
FooMsg msg -> | |
{ model | foo = Foo.update msg model.foo } | |
Bar -> | |
{ model | bar = 34 } | |
view : Model -> Html Msg | |
view model = | |
section [] | |
[ text <| toString model | |
, button [ onClick (FooMsg Foo.Uno) ] [ text "Foo.Uno" ] | |
, button [ onClick (FooMsg Foo.Dos) ] [ text "Foo.Dos" ] | |
, button [ onClick Bar ] [ text "Bar" ] | |
] | |
main : Program Never Model Msg | |
main = | |
beginnerProgram | |
{ update = update | |
, view = view | |
, model = { foo = 0, bar = 0 } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment