uncover-co / elm-admin-alpha / Admin.Actions

Actions are a especial kind of Cmd that can be used to trigger both your usual commands as well as especial ones used by ElmAdmin.

You can use commands that will be handled by your own update functions.

import ElmAdmin.Actions as Actions

update : RouteParams -> Msg -> Model -> ( Model, Action Msg )
update _ msg model =
    case msg of
        RequestedUsers ->
            ( model
            , Actions.cmd <| fetchUsers GotUsers
            )

        GotUsers users ->
            ( { model | users = users }
            , Actions.none
            )

But you can also trigger actions that will be handled by ElmAdmin itself.

import ElmAdmin.Actions as Actions

update : RouteParams -> Msg -> Model -> ( Model, Action Msg )
update _ msg model =
    case msg of
        RequestedUsers ->
            ( model
            , Actions.cmd <| fetchUsers GotUsers
            )

        GotUsers users ->
            ( { model | users = users }
            , Actions.showNotification <|
                text "Got some users!"
            )

Commands

cmd : Platform.Cmd.Cmd msg -> Action msg

Sends a command that will be handled by your update functions.

none : Action msg

Does nothing. This is similar to Cmd.none.

batch : List (Action msg) -> Action msg

Batchs a list of actions. You can mix and match your cmds and ElmAdmin actions by using this function.

map : (msgA -> msgB) -> Action msgA -> Action msgB

Maps an Action msgA to an Action msgB. Useful for submodules.


type alias Action msg =
Admin.Shared.Action msg

Notifications

You can trigger a notification popup from anywhere in your application through one of these commands.

showNotification : Html msg -> Action msg

Triggers a notification that will fade out after a while.

showHighlightNotification : Html msg -> Action msg

Triggers a notification with a "highlight" theme.

showSuccessNotification : Html msg -> Action msg

Triggers a notification with a "success" theme.

showWarningNotification : Html msg -> Action msg

Triggers a notification with a "warning" theme.

showDangerNotification : Html msg -> Action msg

Triggers a notification with a "danger" theme.

Form

initForm : Admin.Form.Form model msg params resource -> resource -> Action msg

Set a form state based on a resource.

debounce : String -> Basics.Int -> msg -> Action msg

Debounce a message passing a string as a debounce key and a wait time in milliseconds.