getto-systems / elm-command / Getto.Command

utility of Cmd

Construction

none : model -> ( model, Platform.Cmd.Cmd msg )

create 'Do nothing' command

model |> Command.none
-- ( model, Cmd.none )

Helper

map : (msg -> super) -> ( model, Platform.Cmd.Cmd msg ) -> ( model, Platform.Cmd.Cmd super )

map Cmd msg in command tuple

type Msg
  = Sub SubMsg

type SubMsg
  = HelloWorld

update : Msg -> Model -> ( Model, Cmd Msg )
update message model =
  case message of
    Sub msg ->
      model |> updateSub msg |> Command.map Sub


updateSub : SubMsg -> Model -> ( Model, Cmd SubMsg )
updateSub message model =
  case message of
    HelloWorld -> ( model, Cmd.none )

Chaining

andThen : (model -> ( model, Platform.Cmd.Cmd msg )) -> ( model, Platform.Cmd.Cmd msg ) -> ( model, Platform.Cmd.Cmd msg )

merge 'Cmd msg' in command tuple

type Msg
  = HelloWorld

init : ( Model, Cmd Msg )
init =
  ( (), Cmd.none )
  |> Command.andThen updateA
  |> Command.andThen updateB

updateA : ( Model, Cmd Msg )
updateA model = ( model, Cmd.none )

updateB : ( Model, Cmd Msg )
updateB model = ( model, Cmd.none )