forked from DockYard/live_view_demo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from alexwolf47/alex/tidying-up-all-ui
Alex/tidying up all ui
- Loading branch information
Showing
7 changed files
with
126 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
defmodule PhoenixRoyale.GameChat do | ||
use GenServer | ||
|
||
@server_name {:global, __MODULE__} | ||
|
||
def start_link(_init_args) do | ||
# you may want to register your server with `name: __MODULE__` | ||
# as a third argument to `start_link` | ||
GenServer.start_link(__MODULE__, %{messages: []}, name: @server_name) | ||
end | ||
|
||
def init(server) do | ||
{:ok, server} | ||
end | ||
|
||
def state() do | ||
GenServer.call(@server_name, :state) | ||
end | ||
|
||
def new_message(author, content) do | ||
GenServer.cast(@server_name, {:new_message, author, content}) | ||
end | ||
|
||
def handle_call(:state, _from, state) do | ||
{:reply, state, state} | ||
end | ||
|
||
def handle_cast({:new_message, author, content}, state) do | ||
if content == "" do | ||
{:noreply, state} | ||
else | ||
message = {author, content} | ||
{:noreply, %{state | messages: [message | state.messages]}} | ||
end | ||
end | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters