The second paragraph on page 221 describes the demographic display logic:
… If no demographic exists, and the socket assigns key of
:demographic
points tonil
, the template renders the demographic form. Otherwise, we render the demographic show component and call on theRatingLive.Index.products/1
function component to add the product ratings to our view.
The logic in survey_live.html.heex
is reversed. The code tests for the existence of @demographic
rather than it’s non-existence:
<%= if @demographic do %>
<DemographicLive.Show.details demographic={@demographic} />
<hr />
<br/>
<RatingLive.Index.product_list products={@products}
current_user={@current_user} />
<% else %>
<!-- ... -->
<% end %>
Also, the first sentence shown above contains the phrase “points to nil
.” Earlier, on page 197, the book used the phrase “set to nil
”:
So, the
:demographic
key in socket assigns could be set to a demographic struct, or it could be set tonil
.
Could the description be reordered to match the code? Perhaps:
… If a demographic exists, the
:demographic
key in socket assigns will be set to a demographic struct; the template renders the demographic show component and calls theRatingLive.Index.products/1
function component to add the product ratings to our view. Otherwise, the:demographic
key in socket assigns will be set tonil
; the template renders the demographic form.