From acba4ea11e4c60bfab34dd0478c91d3c48c80d0d Mon Sep 17 00:00:00 2001 From: Tom Nunn Date: Wed, 13 Jul 2022 08:14:36 +0200 Subject: [PATCH] Add Effect.map --- src/Internal/Effect.elm | 25 ++++++++++++++++++++++++- src/Select/Effect.elm | 17 +++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Internal/Effect.elm b/src/Internal/Effect.elm index 8f3864d..4abbf15 100644 --- a/src/Internal/Effect.elm +++ b/src/Internal/Effect.elm @@ -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 diff --git a/src/Select/Effect.elm b/src/Select/Effect.elm index b6aa913..7859c03 100644 --- a/src/Select/Effect.elm +++ b/src/Select/Effect.elm @@ -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