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

abtin
page 20: … protoc command… I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New
simonpeter
When I try the command to create a pair of migration files I get an error. user=> (create-migration "guestbook") Execution error (Ill...
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> render() but the correc...
New
cro
I am working on the “Your Turn” for chapter one and building out the restart button talked about on page 27. It recommends looking into ...
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
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
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
brunogirin
When running tox for the first time, I got the following error: ERROR: InterpreterNotFound: python3.10 I realised that I was running ...
New
mert
AWDWR 7, page 152, page 153: Hello everyone, I’m a little bit lost on the hotwire part. I didn’t fully understand it. On page 152 @rub...
New
davetron5000
Hello faithful readers! If you have tried to follow along in the book, you are asked to start up the dev environment via dx/build and ar...
New

Other popular topics Top

AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
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
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
New
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
PragmaticBookshelf
Author Spotlight: Tammy Coron @Paradox927 Gaming, and writing games in particular, is about passion, vision, experience, and immersio...
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
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 ❯