On Saturday, January 28, 2017 at 10:58:22 PM UTC, Robert Woodhead wrote:
>
> I know just enough about Elm to be a true danger to myself and everyone in 
> my immediate vicinity, so I am not sure if this is a good idea. However, 
> even if it is not, I learned a few things while coding it up.
>

Have you looked into Out messages in Elm? What you have done is similar to 
that, except you have also added a routing layer in the top-level to feed 
out messages (memos) from one module into another.

Here is an out messages helper library (which is also overkill for many 
situations):

http://package.elm-lang.org/packages/folkertdev/outmessage/latest

I have also implemented a messaging module based on code lifted from 
gdotdesign/elm-ui, which you can find here:

https://github.com/rupertlssmith/elmq

As you get more experience with elm, you might find that you need this kind 
of inter module communication less than you think you might. If 2 modules 
need to talk to each other a lot, it could be an indication that you have 
not chosen the best way to divide your code into modules and re-considering 
that might be worth pursuing.

Recently I had some code where a parent module was sending a Msg to a child 
to invoke a particular state change. That meant that the child module had 
to expose its constructors for the Msg type. I decided this was a bad thing 
and that the Msg type is best left opaque. So I just pulled out that update 
action into its own function with type ChildModel -> ChildModel, exposed 
that, and call it from within the parents update function. The internal Msg 
type of a module needs to be exposed to the outside so that Cmd.map can be 
used to direct its events to it, but IMO its constructors are best kept 
private.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to