Hi Joaquín,

If you expect the component to do HTTP request internally and return the 
result, I think it is (Model, Cmd msg, Whatever) pettern, which Evan is 
going to explain here 
<http://guide.elm-lang.org/architecture/components/communication.html>.

Using this pattern, I recently implemented a similar thing too (It's a 
SearchBox 
<https://github.com/jinjor/office-maker/blob/master/src/elm/SearchBox.elm>). 
This component has an input for query and triggers submit event as Msg. 
This Msg comes back to the `update` function, and if the query is valid, 
then HTTP request occurs through Cmd. After the result comes back, it then 
goes out of the component as an Event.

(Its Model has `results` field in it, but I think this is not necessary. 
Throwing the result with Event would also be good way.)

I'm not sure this is really following the official way, but I hope this 
helps.


2016年5月17日火曜日 18時07分31秒 UTC+9 Joaquín Oltra:
>
> I've changed my previous attempt so that instead of App knowing about and 
> acting on the Msg types from the child SearchForm component, now I'm making 
> the SearchForm return an event as suggested in the docs (making the update 
> function return extra info for parent).
>
> I'm liking it better than the thing I did before: 
> https://github.com/joakin/gimme-gif/commit/d5ed1ef0296bb87f84b12eec0ad8ef95f1630008
>
> This way the parent routes all child msgs to the child, and after update 
> sees if there is anything of interest for him:
>
> update msg model =
>   case Debug.log "MSG: " msg of
>     SearchForm sfmsg ->
>       let
>         (sfmodel, event) = SearchForm.update sfmsg model.search
>       in
>         ( { model | search = sfmodel }
>         , case event of
>             Just SearchForm.Search ->
>               getRandomGif model.search
>             Nothing ->
>               Cmd.none
>         )
>
>
> Is this any better?
>
> On Monday, May 16, 2016 at 9:59:05 PM UTC+2, Joaquín Oltra wrote:
>>
>> Hi, I'm trying to learn how to properly extract components that have a 
>> model and update functions to standalone components, but I'm not sure if 
>> I'm doing a good job.
>>
>> The guide I've found incomplete on nesting, the todomvc example is just 
>> one file, and I can't find good info around. I'd really appreciate some 
>> code review.
>>
>> It is the gif app, I'm trying to extract the search form, which has 
>> internal state (the query in the input), but also has a message that the 
>> parent is interested in (submit on the form) in order to trigger the gif 
>> fetching.
>>
>>
>> https://github.com/joakin/gimme-gif/commit/a6bf98da1f7f018a29456930a1886c9fa908bde3
>>
>> Even if the SearchForm doesn't return Cmds, I'm trying to properly merge 
>> them with the ones on the parent to get the idea. Would this be how you'd 
>> do it?
>>
>> Thanks a lot, my brain hurts from learning, it is nice :)
>>
>

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