Josh, can you give me some further details? I'm interested to know how 
you'd manage this.


   - How would you choose to send up messages to the root?
   - What is the benefit of wrapping the API calls in a component?


I hope I'm not giving the impression that the API calls are randomly spread 
throughout nested components willy-nilly. All api requests and models are 
tightly encapsulates in an API module. If a component wishes to make an api 
request, it must import the module.

I like this idea of creating a "Service TEA component" - the thought hadn't 
crossed my mind. The component could have a model which manages the 
"CurrentUser" state of the application in a central location. Is this what 
you were alluding to? 




On Tuesday, July 5, 2016 at 10:53:29 AM UTC-4, Josh Adams wrote:
>
> I would handle this entirely differently, personally.  I'm inclined to 
> have an API TEA component as a child at the Root, and send up messages 
> requesting API calls to it.  I would never spread my API requests out 
> through components.
>
> That's just me though - I know other people handle this way differently. 
>  Would love to hear any suggestions from more experienced folks re: this :)
>
> -Josh
> http://www.dailydrip.com/topics/elm
>
> On Tuesday, July 5, 2016 at 7:46:16 AM UTC-5, Erik Lott wrote:
>>
>> My app has several layers of nested components. Various components 
>> throughout the tree will need to interact with our API via http requests. 
>> If any API request returns a 401 - Not Authorized error, or a Timeout 
>> Error, the error needs to bubble up to the root component where is can be 
>> handled appropriately.
>>
>> What is the most idiomatic way of dealing with this? 
>>
>> *1. Parent should pattern match against important child messages*: 
>> Reference 
>> <https://groups.google.com/d/msg/elm-discuss/QPqrJd4C78Y/_TLLg81SAQAJ>
>> This could work, but would be unreasonable in this case. The root 
>> component would need to match against every failing api http request made 
>> by every child, grandchild, great-grandchild, etc, component in the tree. 
>> If a single pattern is missed, the app would be in an error state, so this 
>> is prone to mistakes.
>>
>> *2. Nested Components return additional info from the "update" function*: 
>> Reference 
>> <http://stackoverflow.com/questions/37328203/elm-0-17-how-to-subscribe-to-sibling-nested-component-changes>
>> Each component returns an additional value from its update function like 
>> this:
>> update : Msg -> Model -> (Model, Cmd Msg, SomeInfo)
>>
>> The parent component could inspect the returned "SomeInfo" value from its 
>> direct children, and act on that information if necessary.  In my case, any 
>> nested component that makes http requests to our API would be responsible 
>> for returning a APINotAuthorized and APITimeout value to its parent, and 
>> its parent would do the same, until the error has bubbled up to the root 
>> component.
>>
>>
>> Option 2 is simple and robust, and can be used to pass messages of any 
>> type, for any situation... but I'm wondering if I'm missing an obvious 3rd 
>> solution?
>>
>

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