To state Mark's point clearly: if your view depends on only a small number
of the model's fields, then you are likely to rerender the view only when
some other fields changed, which is unnecessary.
That said, you might not be at the point of needing laziness for
performance. In particular, allocating and copying a new record has a cost
of its own, and you'll have to measure to find if it's worth the lazy call
to the function. Important: because of the virtual DOM, Html.lazy only
saves you the overhead of calling the view function, both its logic and
creating the virtual DOM. If the view function returns virtual DOM that
matches the existing, real DOM, no DOM manipulation is performed, and
that's the real performance win.
So, it is definitely simpler and easier, and possibly no less performant,
to pass the model directly to the view. It would be nice if we could use
the type system to limit which fields of the model the view can see, so we
can isolate it better for understanding and testing. Fortunately there is a
neat trick that does just that:
view : { r | foo : Int } -> Html Msg
view {foo} = ...
This function accepts any record which has a foo field of type Int. If your
model has that field, it can be passed in, but no other fields in the model
are available to the view function.
--
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.