Skip to content

Instantly share code, notes, and snippets.

@dgmcguire
Created September 14, 2018 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgmcguire/48c7374f9cf548812252c61a4a209717 to your computer and use it in GitHub Desktop.
Save dgmcguire/48c7374f9cf548812252c61a4a209717 to your computer and use it in GitHub Desktop.
on first page load `id` will be nil, so it renders all the things, later you can broadcast out a message to subscribers something like `"conversations:123"` and update on the dynmically generated partial
<div data-texas="conversations"></div>
defmodule ViewModule do
def conversations(_conn, id) when is_nil(id) do
conversations_html = Database.get_conversations()
|> Enum.reduce("", & &2 <> "<div data-texas="conversation" data-texas-id="#{&1.id}">#{&1.text}</div>")
~s|
<div data-texas="conversations">#{conversations_html}</div>
|
end
def conversations(_conn, id) do
~s|
<div data-texas="conversation" data-texas-id="#{id}">
Database.get_conversation(id)
</div>
|
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment