uncover-co / elm-submodules / SubCmd

When setting up a submodule, you should use SubCmd.cmd when you want the submodule itself to handle the messages. However, if you want the message to be "sent" to the host, just use SubCmd.effect.

type alias Model =
    { value : String }

type Msg
    = FetchFromServer
    | GotFromServer String
    | Submit

type Effect
    = SendValue String

update : Msg -> Model -> ( Model, SubCmd Msg Effect )
update msg model =
    case msg of
        FetchFromServer ->
            ( model
            , SubCmd.cmd (fetchFromServer GotFromServer)
            )

        GotFromServer value ->
            ( { value = value }, SubCmd.none )

        Submit ->
            ( model, SubCmd.effect (SendValue model.value) )

Functions


type alias SubCmd msg effect =
SubModule.SubCmd msg effect

none : SubCmd msg effect

cmd : Platform.Cmd.Cmd msg -> SubCmd msg effect

effect : effect -> SubCmd msg effect

batch : List (SubCmd msg effect) -> SubCmd msg effect

With batch you can actually send cmd's and effect's at the same time!

Submit ->
    ( model, SubCmd.batch
        [ SubCmd.effect (SendValue model.value)
        , SubCmd.cmd (fetchFromServer GotFromServer)
        ]
    )

Transformations

mapCmd : (msgA -> msgB) -> SubCmd msgA effect -> SubCmd msgB effect

Maps a cmd just like you would with Cmd.map.

mapEffect : (effectA -> effectB) -> SubCmd msg effectA -> SubCmd msg effectB

Maps an effect just like you would with Cmd.map.

mapBoth : (msgA -> msgB) -> (effectA -> effectB) -> SubCmd msgA effectA -> SubCmd msgB effectB

Maps both cmd's and effect's at the same time.