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!

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
jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
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
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex> product = %Product{} %Pento....
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
brian-m-ops
#book-python-testing-with-pytest-second-edition Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
hazardco
On page 78 the following code appears: <%= link_to ‘Destroy’, product, class: ‘hover:underline’, method: :delete, data: { confirm...
New
Keton
When running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New
mcpierce
@mfazio23 I’ve applied the changes from Chapter 5 of the book and everything builds correctly and runs. But, when I try to start a game,...
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
PragmaticBookshelf
Tailwind CSS is an exciting new CSS framework that allows you to design your site by composing simple utility classes to create complex e...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
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
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New
AstonJ
Curious what kind of results others are getting, I think actually prefer the 7B model to the 32B model, not only is it faster but the qua...
New

Sub Categories: