-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Agent for timer state #5
Conversation
Use agent to manage the state of the Timer
@@ -13,9 +13,10 @@ defmodule Stopwatch.Application do | |||
# Start the PubSub system | |||
{Phoenix.PubSub, name: Stopwatch.PubSub}, | |||
# Start the Endpoint (http/https) | |||
StopwatchWeb.Endpoint | |||
StopwatchWeb.Endpoint, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The application will create the timer by calling Stopwatch.Timer.start_link\1
function
lib/stopwatch/timer.ex
Outdated
use Agent | ||
|
||
def start_link(_opts) do | ||
Agent.start_link(fn -> ~T[00:00:00] end, name: __MODULE__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Module name are atoms so we can use it as the name for the timer agent
Using PubSub to have multiple clients listening to the stopwatch
Create test for agent
The stopwatch state is now shared between client using Agent. This can be tested at https://liveview-stopwatch.fly.dev/ |
Add Agent section in Readme
@nelsonic let me know if all this makes sense, thanks |
Create a reset function in the Timer agent. Update the html to display the reset button and handle the "reset" event with liveview
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use agent to manage the state of the Timer