phoenix-pubsub-patterns
Installation
SKILL.md
Phoenix PubSub Patterns
Use this skill before writing ANY PubSub or real-time broadcast code.
Implementation Workflow
- Subscribe in
mount— guard withif connected?(socket)to prevent duplicate subscriptions - Broadcast from context — add a private
broadcast/2helper that fires only on{:ok, result} - Handle in
handle_info/2— update assigns immutably withupdate/3 - Verify with a test — call the context function and assert the LiveView reflects the change
Subscription Pattern
defmodule MyAppWeb.PostLive.Index do
use MyAppWeb, :live_view