Hi!

I'm porting a simple React webapp to Elm, and there is a pattern for not 
rendering a component that I'm not sure how to do cleanly with elm.

The pattern is:

data ? <Component/> : null

In a render method, like in here: 
https://github.com/joakin/gimme-gif/blob/415ff83611ab64ba10eb4f0cddccc12d1192815d/browser/ui/app.js#L13-L15

My translation to Elm has been doing something like:

      if String.isEmpty model.error then
        text ""
      else
        div [ class "Error" ] [ text model.error ]

But it seems verbose and weird, so I figure there are probably better ways 
to accomplish the same.

Any ideas?

Here's some more code with the pattern a couple of times:

view model =
  div
    [ class "App" ]
    [ -- Other nodes here...
      if String.isEmpty model.error then
        text ""
      else
        div [ class "Error" ] [ text model.error ]
    , if String.isEmpty model.gif then
        text ""
      else
        div [ class "Gif" ]
          [ input [ type' "text", readonly True, value model.gif ] []
          , img [ src model.gif ] []
          ]
    ]




ps: I'm keeping the state of the Error, Gif, etc separate because they are 
independent, there may be none to show, just the error, no error but a gif, 
and maybe both error and a gif.

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