okari5678

okari5678

Programming Phoenix LiveView:

socket is being accessed in the function body, hence the need to include it in the function head.
Current:
def maybe_track_user(

  •     product,*
    
  •     %{assigns: %{live_action: :show, user_token: user_token}}*
    
  •     ) do*
    
  •            if connected?(socket) do*
    
  •            user = Accounts.get_user_by_session_token(user_token)*
    
  •            # do tracking here!*
    
  • end*

Expected:
def maybe_track_user(

  •  product,*
    
  •  %{assigns: %{live_action: :show, user_token: user_token}} **= socket***
    
  •  ) do*
    
  •          if connected?(socket) do*
    
  •          user = Accounts.get_user_by_session_token(user_token)*
    
  •         # do tracking here!*
    

end

Title: Programming Phoenix LiveView: B3.0: Include “=socket” in function header (page 255)
Example: Programming Flutter - ‘pub get’ command not working (page 15)

Please also add the book’s tag if it has not already present, thanks!

0 938 3

Marked As Solved

SophieDeBenedetto

SophieDeBenedetto

Author of Programming Phoenix LiveView

Hi! Thanks for submitting your question. It does in fact look like there is a mistake in that code! The correct case statement should read like this:

case Presence.get_by_key("user_activity", product.name) do
  [] ->
    Presence.track(
      pid,
      "user_activity",
      product.name, %{users: [%{email: user.email}]}
    )

  %{metas: [%{users: active_users_for_product}]} ->
    Presence.update(pid, "user_activity", product.name, %{
      users: [active_users_for_product | %{email: user.email}]
    })
end

You’ll find that updated in the next Beta release. In the meantime, you can copy in the correction from this comment.

Where Next?

Popular Pragmatic Bookshelf topics Top

New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> render() but the correc...
3 1296 17
New
HarryDeveloper
Hi @venkats, It has been mentioned in the description of ‘Supervisory Job’ title that 2 things as mentioned below result in the same eff...
0 2222 2
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex> product = %Product{} %Pento....
0 1798 20
New
jskubick
I’m running Android Studio “Arctic Fox” 2020.3.1 Patch 2, and I’m embarrassed to admit that I only made it to page 8 before running into ...
0 1696 3
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
0 3500 3
New
Charles
In general, the book isn’t yet updated for Phoenix version 1.6. On page 18 of the book, the authors indicate that an auto generated of ro...
9 2047 12
New
akraut
The markup used to display the uploaded image results in a Phoenix.LiveView.HTMLTokenizer.ParseError error. lib/pento_web/live/product_l...
2 2083 9
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
0 1506 3
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....
0 1005 3
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 ...
245 5335 101
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...
38 4062 19
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
212 15008 90
New
Rainer
My first contact with Erlang was about 2 years ago when I used RabbitMQ, which is written in Erlang, for my job. This made me curious and...
195 6396 95
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...
105 14440 47
New
DevotionGeo
The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
21 11128 7
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
155 4360 65
New
New
PragmaticBookshelf
Author Spotlight Erin Dees @undees Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
24 3704 11
New
PragmaticBookshelf
Author Spotlight: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
72 3959 21
New

Sub Categories: