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 Pragmatic topics Top

kuroneko
Whilst the author has been careful to provide exact results for the tests elsewhere in the book (such as surds with the transformation te...
New
iPaul
page 37 ANTLRInputStream input = new ANTLRInputStream(is); as of ANTLR 4 .8 should be: CharStream stream = CharStreams.fromStream(i...
New
belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New
yulkin
your book suggests to use Image.toByteData() to convert image to bytes, however I get the following error: "the getter ‘toByteData’ isn’t...
New
lirux
Hi Jamis, I think there’s an issue with a test on chapter 6. I own the ebook, version P1.0 Feb. 2019. This test doesn’t pass for me: ...
New
New
adamwoolhether
When trying to generate the protobuf .go file, I receive this error: Unknown flag: --go_opt libprotoc 3.12.3 MacOS 11.3.1 Googling ...
New
patoncrispy
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New
adamwoolhether
I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New

Other popular topics Top

dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
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
PragmaticBookshelf
Build highly interactive applications without ever leaving Elixir, the way the experts do. Let LiveView take care of performance, scalabi...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New
PragmaticBookshelf
Author Spotlight: Tammy Coron @Paradox927 Gaming, and writing games in particular, is about passion, vision, experience, and immersio...
New

Latest in PragProg

View all threads ❯