elm-pages-v3-beta/examples/docs/app/Effect.elm
2022-03-21 13:12:36 -07:00

52 lines
853 B
Elm

module Effect exposing (Effect(..), batch, fromCmd, map, none, perform)
import Http
import Json.Decode as Decode
type Effect msg
= None
| Cmd (Cmd msg)
| Batch (List (Effect msg))
none : Effect msg
none =
None
batch : List (Effect msg) -> Effect msg
batch =
Batch
fromCmd : Cmd msg -> Effect msg
fromCmd =
Cmd
map : (a -> b) -> Effect a -> Effect b
map fn effect =
case effect of
None ->
None
Cmd cmd ->
Cmd (Cmd.map fn cmd)
Batch list ->
Batch (List.map (map fn) list)
perform : (pageMsg -> msg) -> Effect pageMsg -> Cmd msg
perform fromPageMsg effect =
case effect of
None ->
Cmd.none
Cmd cmd ->
Cmd.map fromPageMsg cmd
Batch list ->
Cmd.batch (List.map (perform fromPageMsg) list)