Skip to content

Instantly share code, notes, and snippets.

@vietlq
Forked from freakingawesome/so-39628628.elm
Created December 22, 2017 07:58
Show Gist options
  • Save vietlq/a074ff0ebb5ead7e507c1014544a9e33 to your computer and use it in GitHub Desktop.
Save vietlq/a074ff0ebb5ead7e507c1014544a9e33 to your computer and use it in GitHub Desktop.
import Html exposing (..)
import Html.Events exposing (..)
main : Program Never Model Msg
main =
Html.program
{ init = init
, view = view
, update = update
, subscriptions = \_ -> Sub.none
}
type alias Model =
{ message : String
}
type Msg
= One
| Two
| Three
| ChainMsgs (List Msg)
init = { message = "initializing" } ! []
update msg model =
case msg of
ChainMsgs msgs ->
let
chain msg1 (model1, cmds) =
let (model2, cmds1) = update msg1 model1
in model2 ! [ cmds, cmds1 ]
in
List.foldl chain (model ! []) msgs
_ ->
{ model | message = model.message ++ ", " ++ toString msg } ! []
view model =
div []
[ div []
[ button [ onClick (ChainMsgs [One, Two, Three]) ] [ text "Click me" ]
]
, text model.message
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment