Skip to content

Instantly share code, notes, and snippets.

@mrVanDalo
Created March 3, 2018 04:56
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 mrVanDalo/5158ad9a34aa7f5d9f3a67e6c9249771 to your computer and use it in GitHub Desktop.
Save mrVanDalo/5158ad9a34aa7f5d9f3a67e6c9249771 to your computer and use it in GitHub Desktop.
Elm problem to Route Cmds to Subs
{-| 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