Skip to content

Instantly share code, notes, and snippets.

@nqthqn
Created July 17, 2017 23:16
Show Gist options
  • Save nqthqn/5843404710c279427203a582a1bef488 to your computer and use it in GitHub Desktop.
Save nqthqn/5843404710c279427203a582a1bef488 to your computer and use it in GitHub Desktop.
message wrapping
module Foo exposing (..)
type Msg
= Uno
| Dos
| Tres
update msg foo =
case msg of
Uno ->
1
Dos ->
2
Tres ->
3
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