Add Effect.map

This commit is contained in:
Tom Nunn 2022-07-13 08:14:36 +02:00
parent 03838bd980
commit acba4ea11e
2 changed files with 41 additions and 1 deletions

View File

@ -1,4 +1,4 @@
module Internal.Effect exposing (Effect(..), batch, none, perform, simulate)
module Internal.Effect exposing (Effect(..), batch, map, none, perform, simulate)
import Browser.Dom as Dom
import Process
@ -144,3 +144,26 @@ calculateScrollTop { optionTop, optionBottom, menuViewPortY, menuHeight } =
else
menuViewPortY
map : (msg -> msg2) -> Effect effect msg -> Effect effect msg2
map toMsg effect =
case effect of
GetContainerAndMenuElements msg ids ->
GetContainerAndMenuElements (msg >> toMsg) ids
GetElementsAndScrollMenu msg ids ->
GetElementsAndScrollMenu (toMsg msg) ids
Batch effects ->
List.map (map toMsg) effects
|> Batch
Request eff ->
Request eff
Debounce msg delay val ->
Debounce (msg >> toMsg) delay val
None ->
None

View File

@ -4,6 +4,7 @@ module Select.Effect exposing
, perform, performWithRequest
, simulate, simulateWithRequest
, SimulateInputConfig, simulateFillIn, simulateArrowDown, simulateArrowUp, simulateClickOption, simulateEnterKey
, map
)
{-| Update the Select by returning Effects instead of Cmds.
@ -36,6 +37,11 @@ you don't need this module.
@docs SimulateInputConfig, simulateFillIn, simulateArrowDown, simulateArrowUp, simulateClickOption, simulateEnterKey
# Mapping
@docs map
-}
import Html
@ -339,6 +345,17 @@ simulateClickOption config model optionLabel =
-- MAP
{-| Map Effect from one msg type to another
-}
map : (msg -> msg2) -> Effect effect msg -> Effect effect msg2
map =
Effect.map
-- INTERNAL