Skip to content

Instantly share code, notes, and snippets.

@Janiczek
Last active November 23, 2021 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Janiczek/e0610c9d236ef0839a87fa00bd7f0475 to your computer and use it in GitHub Desktop.
Save Janiczek/e0610c9d236ef0839a87fa00bd7f0475 to your computer and use it in GitHub Desktop.
Two child-parent view patterns
module ConfigChild exposing (Config, Msg, view)
import Html exposing (Html)
import Html.Events
type Msg
= LaunchTheNukes
type alias Config msg =
{ msg : Msg -> msg
}
view : Config msg -> Html msg
view config =
Html.button
[ Html.Events.onClick (config.msg LaunchTheNukes) ]
[]
module ConfigParent exposing (Msg, view)
import Html exposing (Html)
import ConfigChild
type Msg
= ChildMsg ConfigChild.Msg
view : Html Msg
view =
Html.div []
[ ConfigChild.view
{ msg = ChildMsg }
]
module MappingChild exposing (Msg, view)
import Html exposing (Html)
import Html.Events
type Msg
= LaunchTheNukes
view : Html Msg
view =
Html.button
[ Html.Events.onClick LaunchTheNukes ]
[]
module MappingParent exposing (Msg, view)
import Html exposing (Html)
import MappingChild
type Msg
= ChildMsg MappingChild.Msg
view : Html Msg
view =
Html.div []
[ MappingChild.view
|> Html.map ChildMsg
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment