# `PhoenixMountable.PubSub`
[🔗](https://github.com/hattoriai/phoenix_mountable/blob/v0.2.1/lib/phoenix_mountable/pubsub.ex#L2)

PubSub topics scoped to a mount.

Users of the same mount see each other's changes live; two mounts of the
same library (or two libraries) never share a topic. Messages travel across
the cluster like any `Phoenix.PubSub` message.

    # in a LiveView of the library
    PhoenixMountable.PubSub.subscribe(socket.assigns.mount, "items")

    # anywhere, after a change
    PhoenixMountable.PubSub.broadcast(mount, "items", {:item_updated, item})

The PubSub server is the mount's `:pubsub` option, or the host endpoint's
`:pubsub_server`.

# `broadcast`

```elixir
@spec broadcast(PhoenixMountable.Mount.t(), String.t(), term()) ::
  :ok | {:error, term()}
```

Broadcasts `message` to the subscribers of `topic` in the mount, on all nodes.

# `broadcast_from`

```elixir
@spec broadcast_from(PhoenixMountable.Mount.t(), String.t(), term()) ::
  :ok | {:error, term()}
```

Like `broadcast/3`, but not to the caller.

# `local_broadcast`

```elixir
@spec local_broadcast(PhoenixMountable.Mount.t(), String.t(), term()) :: :ok
```

Like `broadcast/3`, but only on this node.

# `server!`

```elixir
@spec server!(PhoenixMountable.Mount.t()) :: atom()
```

The PubSub server of the mount.

# `subscribe`

```elixir
@spec subscribe(PhoenixMountable.Mount.t(), String.t()) :: :ok | {:error, term()}
```

Subscribes the caller to `topic` in the mount.

# `topic`

```elixir
@spec topic(PhoenixMountable.Mount.t(), String.t()) :: String.t()
```

The full topic name for `topic` in the mount.

# `unsubscribe`

```elixir
@spec unsubscribe(PhoenixMountable.Mount.t(), String.t()) :: :ok
```

Unsubscribes the caller from `topic` in the mount.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
