-
-
Save vietlq/a074ff0ebb5ead7e507c1014544a9e33 to your computer and use it in GitHub Desktop.
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
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