jshprentz

jshprentz

Programming Phoenix LiveView B10.0: Demographic display logic explanation does not match code (page 221)

The second paragraph on page 221 describes the demographic display logic:

… If no demographic exists, and the socket assigns key of :demographic points to nil, the template renders the demographic form. Otherwise, we render the demographic show component and call on the RatingLive.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 to nil.

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 the RatingLive.Index.products/1 function component to add the product ratings to our view. Otherwise, the :demographic key in socket assigns will be set to nil; the template renders the demographic form.

Marked As Solved

SophieDeBenedetto

SophieDeBenedetto

Author of Programming Phoenix LiveView

Indeed it could! This will be updated before the final release.

Popular Prag Prog topics Top

Razor54672
The answer to 3rd Problem of Chapter 5 (Making Choices) of “Practical Programming, Third Edition” seems incorrect in the given answer ke...
New
jamis
The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
jdufour
Hello! On page xix of the preface, it says there is a community forum "… for help if your’re stuck on one of the exercises in this book… ...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
nicoatridge
Hi, I have just acquired Michael Fazio’s “Kotlin and Android Development” to learn about game programming for Android. I have a game in p...
New
digitalbias
Title: Build a Weather Station with Elixir and Nerves: Problem connecting to Postgres with Grafana on (page 64) If you follow the defau...
New
s2k
Hi all, currently I wonder how the Tailwind colours work (or don’t work). For example, in app/views/layouts/application.html.erb I have...
New
New
roadbike
From page 13: On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
New

Other popular topics Top

AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
AstonJ
I’ve been hearing quite a lot of comments relating to the sound of a keyboard, with one of the most desirable of these called ‘thock’, he...
New
foxtrottwist
Here’s our thread for the Keyboardio Atreus. It is a mechanical keyboard based on and a slight update of the original Atreus (Keyboardio ...
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
OvermindDL1
Woooooooo! This is such a huge release for it, and 2 years incoming! In short, the library is now using an updated hyper backend (not j...
New

Latest in PragProg

View all threads ❯