>
> (In the UserInfo "update" function if cannot return a command(effect)
> "Ratings Reload" directly, because of this "Cmd.map UserInfo effect")
>

It seems to me that you should not be wrapping "Loaded" in a "UserInfo"
action. Judging from your update function, I am guess your main action type
looks like:

type Action = UserInfo UserInfo.Action | Ratings Ratings.Action

Here, these are wrappers for actions that are dealt with in one module of
your program or another. I suggest that you modify this to be

type Action = Loaded | UserInfo UserInfo.Action | Ratings Ratings.Action

Because "Loaded" has consequences in both of your components, it ought to
be dealt with in your main update function.


On Mon, Nov 28, 2016 at 5:37 AM, <[email protected]> wrote:

> Hi All,
> I know that Elm doesn't have the concept of components but instead it has
> triplets. They should behave similar to components, they encapsulate
> internal implementations.
> I use this concept in my App and I faced some architectural questions.
> What is the proper or better way to communicate between triplets without
> breaking encapsulation?
> For example, let say I have two "widgets", UserInfo and Ratings. In main
> "update" function I have this
>
>    Ratings act ->
>       let
>         ( ratings, effect ) =
>           Ratings.update act model.ratings
>       in
>         ( { model | ratings = ratings }, Cmd.map Ratings effect )
>
>     UserInfo act ->
>       let
>         ( userInfo, effect ) =
>           UserInfo.update act model.app
>       in
>         ( { model | userInfo = userInfo }, Cmd.map UserInfo effect )
>
>
>
> I have a button "Login" in the UserInfo widget. It will call backend API
> and return the user state.
> Then I want to load and update the Rating widget.
> How and where do this?
>
>
> Should I catch "UserInfo Loaded" event in the main "update"?
> (In the UserInfo "update" function if cannot return a command(effect)
> "Ratings Reload" directly, because of this "Cmd.map UserInfo effect")
>
>    Ratings act ->
>       let
>         ( ratings, effect ) =
>           Ratings.update act model.ratings
>       in
>         ( { model | ratings = ratings }, Cmd.map Ratings effect )
>
>     UserInfo act ->
>       let
>         ( userInfo, effect ) =
>           UserInfo.update act model.app
>
>           cmd =
>                     if act==Loaded
>                     then Cmd.batch [ Cmd.map UserInfo effects, Cmd.message
> (Ratings Reload) ]
>                     else  Cmd.map UserInfo effects
>       in
>         ( { model | userInfo = userInfo },  cmd )
>
>
>
> I feel it will be too messy to keep all this inter-triplet logic here. Is
> there a better way? Maybe  something similar to pub/sub or I'm
> fundamentally wrong here?
>
> --
> 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.
>

-- 
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