PhoenixKitProjects.PubSub (PhoenixKitProjects v0.3.0)

Copy Markdown View Source

Real-time updates for the projects module, backed by PhoenixKit.PubSub.Manager.

Topics

  • "projects:all" — any project/template/task/assignment mutation
  • "projects:tasks" — task library mutations
  • "projects:templates" — template project mutations
  • "projects:project:<uuid>" — updates scoped to one project

Events

Messages are {:projects, event_atom, payload_map} tuples.

Tenant scoping (deferred)

Topics are global today. PhoenixKit core does not currently expose a per-tenant Scope.organization_id or equivalent, and no other feature module (locations, staff, sync, …) does multi-tenant PubSub partitioning either — so this is a framework-wide gap, not a projects-specific one.

When core grows tenant scoping, the right shape here is to thread the org/tenant key into every topic ("projects:org:<org_id>:all", etc.) and have subscribe/1 raise if the scope is missing. Until then, the :project:<uuid> topic is the only one safe against cross-tenant fan-out (you need the UUID to subscribe), and the :all / :tasks / :templates topics deliberately broadcast across all subscribers.

Summary

Functions

Broadcasts an assignment event to the all-projects and the parent project's topic.

Broadcasts a dependency event to the all-projects and the parent project's topic.

Broadcasts an emit-mode UI-intent event to a host-supplied topic.

Broadcasts a project event. Templates also fan out to the templates topic.

Broadcasts a task-library event to the all-projects and tasks topics.

Subscribes the calling process to the given PubSub topic.

Topic for any project, template, task, or assignment mutation.

Topic scoped to a single project.

Topic for task-library mutations.

Topic for template-project mutations.

Functions

broadcast_assignment(event, payload)

Broadcasts an assignment event to the all-projects and the parent project's topic.

broadcast_dependency(event, payload)

Broadcasts a dependency event to the all-projects and the parent project's topic.

broadcast_embed(topic, event, payload)

@spec broadcast_embed(String.t(), atom(), map()) :: :ok

Broadcasts an emit-mode UI-intent event to a host-supplied topic.

Used by PhoenixKitProjects.Web.Helpers when an embedded LV is in emit mode (session["mode"] = "emit"). The host topic is registered by whoever mounts PhoenixKitProjects.Web.PopupHostLive (or any custom host that subscribes directly). Unlike the other broadcast helpers in this module, the topic is NOT one of the canonical projects:* namespaces — it's caller-supplied and opaque to us.

UI-intent verbs (:opened / :closed / :saved / :deleted) are deliberately distinct from the content verbs above (:project_created etc.) so handle_info clauses subscribed to the canonical topics never collide with handlers subscribed to a host topic.

broadcast_project(event, payload)

Broadcasts a project event. Templates also fan out to the templates topic.

broadcast_task(event, payload)

Broadcasts a task-library event to the all-projects and tasks topics.

subscribe(topic)

Subscribes the calling process to the given PubSub topic.

topic_all()

Topic for any project, template, task, or assignment mutation.

topic_project(uuid)

Topic scoped to a single project.

topic_tasks()

Topic for task-library mutations.

topic_templates()

Topic for template-project mutations.