mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-25 12:52:27 +03:00
52 lines
853 B
Elm
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)
|