Last active
November 23, 2021 16:14
-
-
Save Janiczek/e0610c9d236ef0839a87fa00bd7f0475 to your computer and use it in GitHub Desktop.
Two child-parent view patterns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) ] | |
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] | |
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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