Last active
July 11, 2017 18:08
-
-
Save owen-d/b727b9a1a5d4990ed947c6fa7056a92a to your computer and use it in GitHub Desktop.
issue subtyping elm msgs
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 Lib.SubMsg exposing (..) | |
type SubMsg | |
= SubMsgA | |
| SubMsgB |
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 Lib.SubUpdate exposing (..) | |
import Msg exposing (Msg(SubMsg)) | |
import Lib.SubMsg exposing (..) | |
subUpdate : SubMsg -> Model -> (Model, Cmd Msg) | |
subUpdate msg model = | |
case msg of | |
SubMsgA -> | |
... | |
SubMsgB -> | |
... |
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 Msg exposing (..) | |
import Lib.SubMsg exposing (SubMsg) | |
type Msg | |
... | |
| SubMsg Submsg |
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 Update exposing (..) | |
import Msg exposing (Msg(..)) | |
import Lib.SubUpdate exposing (subUpdate) | |
update : Msg -> Model -> (Model, Cmd Msg) | |
update msg model = | |
case msg of | |
... | |
SubMsg msg_ -> | |
subUpdate msg_ model |
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 View exposing (..) | |
import Msg exposing (Msg(SubMsg)) | |
import Lib.SubMsg exposing (SubMsg(SubMsgA, SubMsgB)) | |
import Html exposing (..) | |
view: Model -> Html Msg | |
view model = | |
Html.div [ onClick SubMsgA ] [...] | |
{- Errors: | |
expecting: | |
List (Html Msg) | |
but it is: | |
List (Html SubMsg) | |
-} | |
{- | |
Note: it works if you wrap it with a function like `cast` below. | |
Is there a better way/shorthand to do this? | |
-} | |
cast : (a -> SubMsg) -> a -> Msg | |
cast producer msg = | |
producer msg | |
|> SubMsg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment