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