Skip to content

Instantly share code, notes, and snippets.

@freakingawesome
Last active September 22, 2018 19:04
Show Gist options
  • Save freakingawesome/f6adb3aecaf6366d7c97c0b91d9fba1d to your computer and use it in GitHub Desktop.
Save freakingawesome/f6adb3aecaf6366d7c97c0b91d9fba1d 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
]
@mark-jordanovic-lewis
Copy link

Hej there, I've worked this into a port sending chain to try to get sequential, rather than concurrent, sends to JSLand:

PortChainer ( Ok response ) ->
  let
    newDetails =
      { details | thing = True }
    portCommands = [ Save, Set, Redirect ]
    portChain portMsg (details, portCmds) =
      let ( deets, reducedPortCmds ) = update portMsg details
      in deets ! [portCmds, reducedPortCmds]
  in
    List.foldl portChain ( newDetails ! [] ) portCommands
Save ->
  ( details
  , Port.save details.thing
  )
Set ->
  ( details
  , Port.set details.otherThing
  )
Redirect ->
  ( details
  , Port.redirectTo Urls.redirect
  )

@eboCode
Copy link

eboCode commented Sep 22, 2018

An so-39628628.elm rev for 0.19?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment