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

brianokken
Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not decl...
New
mikecargal
Title: Hands-On Rust (Chapter 11: prefab) Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
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
fynn
This is as much a suggestion as a question, as a note for others. Locally the SGP30 wasn’t available, so I ordered a SGP40. On page 53, ...
New
oaklandgit
Hi, I completed chapter 6 but am getting the following error when running: thread 'main' panicked at 'Failed to load texture: IoError(O...
New
taguniversalmachine
Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New
jonmac
The allprojects block listed on page 245 produces the following error when syncing gradle: “org.gradle.api.GradleScriptException: A prob...
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
jwandekoken
Book: Programming Phoenix LiveView, page 142 (157/378), file lib/pento_web/live/product_live/form_component.ex, in the function below: d...
New
andreheijstek
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
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
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
PragmaticBookshelf
Author Spotlight: Bruce Tate @redrapids Programming languages always emerge out of need, and if that’s not always true, they’re defin...
New
PragmaticBookshelf
A Ruby-Centric Chat with Noel Rappin @noelrappin Once you start noodling around with Ruby you quickly figure out, as Noel Rappi...
New
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New
CommunityNews
In November 2022, I opened issue 99108 on Python’s GitHub repository, arguing that after a recent CVE in its implementation of SHA3, Pyth...
New

Latest in PragProg

View all threads ❯