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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to