Created
March 3, 2018 04:56
-
-
Save mrVanDalo/5158ad9a34aa7f5d9f3a67e6c9249771 to your computer and use it in GitHub Desktop.
Elm problem to Route Cmds to Subs
This file contains hidden or 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
{-| This sketch should show the problem I have. | |
I have 2 Modules. The first Module should "receive" | |
Messages from another module. I could create a large and complex Msg model, | |
OR I could use Cmd and Sub (I think). | |
So my Idea is : | |
Second.Trigger -> Cmd "Send Start" -> Sub "Listen on Start" -> First.Start | |
^------ this is the part which unclear to me | |
I don't want to use ports for that! | |
-} | |
-- | the module that should receive messages from Module Second | |
module First exposing (..) | |
type Msg = Start | Stop | |
type alias Model = { started : Bool } | |
update : Msg -> Model -> Model | |
update msg model = case msg of | |
Start -> { started = True } | |
Stop -> { started = False } | |
subscriptions : Model -> Sub msg | |
subscriptions _ = ListenOnStart Start | |
ListenOnStart : ?? | |
ListenOnStart = ?? | |
-- | the module that should send messages to Module First | |
module Second exposing (..) | |
type Msg = Trigger | |
type alias Model = {} | |
update : Msg -> Model -> (Model, Cmd msg) | |
update Trigger = ( {}, TriggerListenOnStart ) | |
TriggerListenOnStart : ?? | |
TriggerListenOnStart = ?? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment