arcanemachine

arcanemachine

Programming Phoenix LiveView B9.0: Generated code uses streams in LiveView 0.19.x so example code no longer works (p. 94)

Since LiveView now supports Streams, the generated code seems to be pushing the user in that direction as well.

As a result, the example code starting on page 94 (in the “Mount and Render the Product Index” section) no longer matches the code created when I run the generator.

It’s not difficult to work around, but the section should definitely be updated to match the new generator code IMO.

This code from the book:

def mount(_params, _session, socket) do
  {:ok, assign(socket, :products, list_products())}
end

# ...

defp list_products do
  Catalog.list_products()
end

Looks more like this in my generated code:

@impl true
def mount(_params, _session, socket) do
  {:ok, stream(socket, :products, Catalog.list_products())}
end

# ...

defp apply_action(socket, :index, _params) do
  socket
  |> assign(:page_title, "Listing Products")
  |> assign(:product, nil)
end

This code from the book showing how to add data to the socket becomes a little confusing as a result:

def mount(_params, _session, socket) do
  {:ok,
    socket
    |> assign(:greeting, "Welcome to Pento!") # add this line
    |> assign(:products, list_products())}
  end

I ended up doing this instead:

@impl true
def mount(_params, _session, socket) do
  socket = assign(socket, :greeting, "Welcome to Pento!")
  {:ok, stream(socket, :products, Catalog.list_products())}
end

Similar outdated function references occur on page 96.

Marked As Solved

SophieDeBenedetto

SophieDeBenedetto

Author of Programming Phoenix LiveView

Indeed streams will be addressed and used here in the new Beta book version we’re hard at work on right now. Everything will be updated to use the latest LiveView version and functionality.

Popular Prag Prog topics Top

jimschubert
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
New
jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
New
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New
rmurray10127
Title: Intuitive Python: docker run… denied error (page 2) Attempted to run the docker command in both CLI and Powershell PS C:\Users\r...
New
AndyDavis3416
@noelrappin Running the webpack dev server, I receive the following warning: ERROR in tsconfig.json TS18003: No inputs were found in c...
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
brunogirin
When trying to run tox in parallel as explained on page 151, I got the following error: tox: error: argument -p/–parallel: expected one...
New
taguniversalmachine
It seems the second code snippet is missing the code to set the current_user: current_user: Accounts.get_user_by_session_token(session["...
New
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
New
dtonhofer
@parrt In the context of Chapter 4.3, the grammar Java.g4, meant to parse Java 6 compilation units, no longer passes ANTLR (currently 4....
New

Other popular topics Top

ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
wolf4earth
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. https://f...
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
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
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
AstonJ
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me. I think the Planck and the Preonic (o...
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
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
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New

Latest in PragProg

View all threads ❯