How to turn a Msg into a Cmd Msg?

Only Use Sparsely: Better split the update function into multiple smaller functions.

type Msg =
  LoginSucceeded User
  | InfoMessage String
  
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
  case msg of
    LoginSucceeded newUser ->
      ( { model | currentUser = newUser }
      , Cmd.none
      )
    InfoMessage message ->
      ( { model | message = Just message }
      , Cmd.none
      )

Question

How can I display a Message after a user logged in?

Answer

Use the following function:

sendMsg : msg -> Cmd msg
sendMsg msg =
  Task.succeed msg
  |> Task.perform identity

Further reading

Last updated