primait/prima-elm-extra/1.0.0

PrimaCmd

batchMap : List (a -> Cmd msg) -> a -> Cmd msg

Batches the commands returned by the given functions

fetchUsers : Model -> Cmd Msg
serializeData : Model -> Cmd Msg


model
|> batchMap [ fetchUsers, serializeData ]
cmdMap : List (a -> Cmd msg) -> a -> List (Cmd msg)

Maps the given Cmd suppliers to the same value. Usually used like that:

fetchUsers : Model -> Cmd Msg
sendLog : Model -> Cmd Msg
initializeAnalytics : Model -> Cmd Msg


model
    |> cmdMap
        [ fetchUsers
        , sendLog
        , initializeAnalytics
        ]
fromMaybeMap : (a -> Cmd msg) -> Maybe a -> Cmd msg

Returns Cmd.none when argument is Nothing, maps it otherwise

    fromMaybeMap Ports.log Nothing  -- => Cmd.none
    fromMaybeMap Ports.log (Just "hello!") -- => Ports.log "hello!"

Conditionals

ifThenCmd : Bool -> Cmd msg -> Cmd msg
   ifThenCmd True x -- => x
   ifThenCmd False x -- => Cmd.none
ifThenCmdMap : (a -> Bool) -> (a -> Cmd msg) -> a -> Cmd msg
    fetchUsers : Model -> Cmd Msg


    model
    |> ifThenCmdMap Model.usersAreNotPresent
        fetchUsers
ifThenCmds : Bool -> List (Cmd msg) -> Cmd msg
   ifThenCmd True cmds -- => Cmd.batch cmds
   ifThenCmd False x -- => Cmd.none
ifThenCmdsMap : (a -> Bool) -> List (a -> Cmd msg) -> a -> Cmd msg

Like ifThenCmdMap, but with a list of cmds

    fetchUsers : Model -> Cmd Msg
    serializeData : Model -> Cmd Msg


    model
    |> ifThenCmdsMap Model.usersAreNotPresent
        [ fetchUsers
        , serializeData
        ]
ifThenElseCmdMap : (a -> Bool) -> (a -> Cmd msg) -> (a -> Cmd msg) -> a -> Cmd msg

Same as PrimaFunction.ifThenElseMap but for Cmds

model
    |> ifThenElseMap modelHasError
        (Model.toError >> Ports.logError)
        (always () >> Ports.logSuccess)
ifThenElseCmdsMap : (a -> Bool) -> List (a -> Cmd msg) -> List (a -> Cmd msg) -> a -> Cmd msg

Like ifThenCmdMap, but for List of commands

    model
    |> ifThenElseMap modelHasError
        [  Model.toError >> Ports.logError ]
        [ always () >> Ports.logSuccess
        , Ports.serializeModel
        ]
ifThenElseCmds : Bool -> List (Cmd msg) -> List (Cmd msg) -> Cmd msg

Like ifThenElse, but batches Cmds

    ifThenElseMap model.hasError
        [ Ports.logError () ]
        [ Ports.logSuccess () ]

Effects

fromMsgWithDelay : Int -> msg -> Cmd msg

Create a Cmd that triggers the given msg after n milliseconds

fromMsg : msg -> Cmd msg

Lifts a msg to a Cmd.

warning: this is usually an antipattern.

There are specific case in which this can be used (such as flip animations) but unless you encountered such edge cases, be sure to double check if there are different approaches possible