
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 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.
Popular Prag Prog topics










Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /opensuse
- /rust
- /kotlin
- /ruby
- /erlang
- /python
- /clojure
- /react
- /quarkus
- /go
- /vapor
- /react-native
- /v
- /wasm
- /django
- /security
- /nodejs
- /centos
- /rails
- /haskell
- /fable
- /gleam
- /js
- /swift
- /deno
- /tailwind
- /assemblyscript
- /laravel
- /symfony
- /phoenix
- /crystal
- /typescript
- /debian
- /adonisjs
- /julia
- /arch-linux
- /svelte
- /spring
- /c-plus-plus
- /preact
- /flutter
- /actix
- /java
- /angular
- /ocaml
- /zig
- /kubuntu
- /scala
- /zotonic
- /vim
- /rocky
- /lisp
- /html
- /keyboards
- /emacs
- /nim
- /vuejs
- /nerves
- /elm