Skip to content

Commit

Permalink
add comments to live_channel_view.ex
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjha committed Aug 19, 2019
1 parent 815aa58 commit d7124fe
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/snitch_web/views/live_channel_view.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
defmodule SnitchWeb.LiveChannelView do
use Phoenix.LiveView

#
# When the controller calls live_render/3 this mount/2 function will get called
# after the mount/2 function finishes then the render/1 function will get called
# with the assigns
#
def mount(session, socket) do
channel = session[:channel]
if connected?(socket), do: SnitchWeb.Endpoint.subscribe("channel-updated:#{channel.id}")
Expand All @@ -16,6 +21,15 @@ defmodule SnitchWeb.LiveChannelView do

def render(assigns), do: SnitchWeb.ChannelView.render("show_active.html", assigns)

#
# Since the mount/2 function called "subscribe" to with the identifier
# "channel-updated:#{channel.id}" then anytime data is broadcast this
# handle_info/2 function will run and we have the power to set new values
# with set_assigns/2
#
# After we assign new values, the render/1 function will get called with the
# new assigns
#
def handle_info(channel, socket) do
{
:noreply,
Expand Down

0 comments on commit d7124fe

Please sign in to comment.