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

johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
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
jdufour
Hello! On page xix of the preface, it says there is a community forum "… for help if your’re stuck on one of the exercises in this book… ...
New
Chrichton
Dear Sophie. I tried to do the “Authorization” exercise and have two questions: When trying to plug in an email-service, I found the ...
New
leba0495
Hello! Thanks for the great book. I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorre...
New
adamwoolhether
When trying to generate the protobuf .go file, I receive this error: Unknown flag: --go_opt libprotoc 3.12.3 MacOS 11.3.1 Googling ...
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
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
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
dachristenson
I’ve got to the end of Ch. 11, and the app runs, with all tabs displaying what they should – at first. After switching around between St...
New

Other popular topics Top

Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
PragmaticBookshelf
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
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
PragmaticBookshelf
Author Spotlight: Tammy Coron @Paradox927 Gaming, and writing games in particular, is about passion, vision, experience, and immersio...
New
sir.laksmana_wenk
I’m able to do the “artistic” part of game-development; character designing/modeling, music, environment modeling, etc. However, I don’t...
New

Sub Categories: