Skip to content

Latest commit

 

History

History

module-composition-tagger

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Module composition in Elm with tagger function

Example app, featuring the usage of tagger function for message mapping in view composition.

The term is originated from official docs, where a function with type signature of a -> msg is defined as tagger

It is also often referred as Translator pattern.

Motivation

The key takeaway of this example is that you can use the second argument of Html.App.map to have more control over the message flow in your top-level update function.

The idea, introduced in the article, improves on tagger formula and might be used as an inspiration for generic APIs.

Please consider this example:

import Child


type Msg
    = SomeMsg
    | ToChild Child.Msg


-- Tagger function, for better control over the message flow.


tagger : Child.Msg -> Msg 
tagger msg =
    case msg of
        Child.SomeMsg ->
            SomeMsg
            
        _ ->
            ToChild msg


-- Top-level view


view : Model -> Html Msg
view model =
    Cmd.map tagger (Child.view model.childState)
    

Building the example

$ elm make Main.elm