herminiotorres

herminiotorres

Programming Phoenix LiveView - Version B5.0

On Chapter 3 - Page 78, the beginning of the page has this code here:

@doc """
 Maybe it is missing to put the Pento context before Catalog.Product.Query?
"""
defmodule Catalog.Product.Query do
  ...
  def base_product_query, do: Product
  
  def cheaper_than(query, price), do: from in query, where...
  
  def cheap_product_skus(price)
    base_product_query()
    |> chaper_than(price)
    |> skus
  end
  ...
end

And for the code almost to the bottom, has some typos. Like:

defmodule Pento.Catalog do
  alias Catalog.Product.Query
  alias Pento.Repo

  def run_query(query) do
    {:ok, list} = Repo.all(query)
    list
  end

  def send_sale_skus(query) do
    query
    |> Product.cheap_product_skus(25.00) # Typo: Query.cheap_product_skus(25.00)
    |> run_query
    |> Service.send_bargains # Question: the name of the module it is only Service?
  end
end

Also, for the next page 79, has more typos too, like:

defmodule Pento.Catalog do
  alias Catalog.Product.Query
  alias Pento.Repo

  @doc """
   For the Repo.all API, has only three options:
   1. Empty List without any items.
   2. List with one or more items.
   3. Query doesn't work and raise an error.
   """
  def run_query(query) do
    Repo.all(query)
  end

  def send_sale_skus(query) do
    query
    |> Product.cheap_product_skus(25.00) # Typo: Query.cheap_product_skus(25.00)
    |> run_query
  end

  def send_sale_skus(query)
    with {:ok, products} <- send_sale_skus(query), # this line of code here, never pattern matching
         {:ok, response} <- Service.send_bargains(products) do # when this line of code it fails? Returns as a tuple with {:error, reason} ?
      response
    else
       # if some error or cas doesn't pattern match in with conditions it will failure here a raise an error with unclause matching.
      {:error, reason} ->
        IO.puts "Error sending sale skus: #{reason}"
    end
  end
end

After words this is my feedback even these code as an example, and not intended to use. Besides, I use common comments as #, and some others I use @doc to get my point of view.

Marked As Solved

SophieDeBenedetto

SophieDeBenedetto

Author of Programming Phoenix LiveView

Thank you for catching these! We’ll fix them for the next release :slight_smile:

Also Liked

SophieDeBenedetto

SophieDeBenedetto

Author of Programming Phoenix LiveView

Thank you so much for sharing this feedback @herminiotorres! I’ve made some changes to fix the typo and to provide a better example of when to use with statements in your Phoenix context. You’ll find those changes in the next release :slight_smile: :slight_smile:

Where Next?

Popular Pragmatic Bookshelf topics Top

GilWright
Working through the steps (checking that the Info,plist matches exactly), run the demo game and what appears is grey but does not fill th...
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
mikecargal
Title: Hands-on Rust: question about get_component (page 295) (feel free to respond. “You dug you’re own hole… good luck”) I have somet...
New
raul
Hi Travis! Thank you for the cool book! :slight_smile: I made a list of issues and thought I could post them chapter by chapter. I’m rev...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex&gt; product = %Product{} %Pento....
New
gilesdotcodes
In case this helps anyone, I’ve had issues setting up the rails source code. Here were the solutions: In Gemfile, change gem 'rails' t...
New
jskubick
I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint. As entered, the SwitchCompat changes color to hol...
New
tkhobbes
After some hassle, I was able to finally run bin/setup, now I have started the rails server but I get this error message right when I vis...
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New
SlowburnAZ
Getting an error when installing the dependencies at the start of this chapter: could not compile dependency :exla, "mix compile" failed...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1036 18873 386
New
axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
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
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
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
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
PragmaticBookshelf
Author Spotlight: Tammy Coron @Paradox927 Gaming, and writing games in particular, is about passion, vision, experience, and immersio...
New
mindriot
Ok, well here are some thoughts and opinions on some of the ergonomic keyboards I have, I guess like mini review of each that I use enoug...
New

Sub Categories: