# `Storehouse.Notify.PubSub`
[🔗](https://github.com/hattoriai/storehouse/blob/v0.2.0/lib/storehouse/notify/pub_sub.ex#L1)

Broadcasts what happens to files (`Storehouse.Notify`) on the app's
`Phoenix.PubSub`, as `{:storehouse, event, info}`.

    config :storehouse,
      notify: {Storehouse.Notify.PubSub, :broadcast, [MyApp.PubSub, {MyApp.Files, :topic, []}]}

    defmodule MyApp.Files do
      # Every file of an account under "accounts/<id>/": its topic.
      def topic(%{file: %{key: "accounts/" <> rest}}), do: "files:" <> hd(String.split(rest, "/"))
      def topic(%{key: "accounts/" <> rest}), do: "files:" <> hd(String.split(rest, "/"))
      def topic(_info), do: nil
    end

The topic is a string, the same for every event, or `{module, function,
args}` called with the event's map first, which gives the topic, or `nil`
to broadcast nothing. In a LiveView:

    def mount(_params, _session, socket) do
      if connected?(socket), do: Phoenix.PubSub.subscribe(MyApp.PubSub, "files:42")
      {:ok, socket}
    end

    def handle_info({:storehouse, :analyzed, %{file: file}}, socket), do: ...

# `broadcast`

```elixir
@spec broadcast(atom(), map(), atom(), String.t() | {module(), atom(), list()}) :: :ok
```

Broadcasts the event on `pubsub`, on the topic (see the module doc).

---

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