-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
104 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
defmodule LiveAdmin.PubSub do | ||
@moduledoc """ | ||
PubSub system for LiveAdmin events. | ||
Currently LiveAdmin has built in support for the following events: | ||
* :job - Shows progress bar indicating status of any ongoing process. LiveAdmin uses this internally to indicate progress of actions on multiple records and tasks. Metadata consists of `pid`, `progress` float/int, and `label` string. | ||
* :announce - Show temporary message with severity level. Meta consists of `message` string, and `type` (`:error`, `:success`, or `:info`) | ||
""" | ||
|
||
@type session_id :: String.t() | ||
|
||
@spec broadcast(session_id, {atom(), map()}) :: :ok | ||
@spec broadcast({atom(), map()}) :: :ok | ||
@doc """ | ||
Notify LiveAdmin of event, consisting of a unique name (either global or scoped to the session, if that is passed) and metadata. | ||
""" | ||
def broadcast(session_id \\ nil, event) do | ||
Phoenix.PubSub.broadcast( | ||
__MODULE__, | ||
if(session_id, do: "session:#{session_id}", else: "all"), | ||
event | ||
) | ||
|
||
:ok | ||
end | ||
|
||
@spec subscribe(session_id) :: :ok | ||
@spec subscribe() :: :ok | ||
@doc """ | ||
Subscribe to LiveAdmin events for a specific session. | ||
""" | ||
def subscribe(session_id), do: Phoenix.PubSub.subscribe(__MODULE__, "session:#{session_id}") | ||
|
||
@doc """ | ||
Subscribe to *all* LiveAdmin events. | ||
""" | ||
def subscribe(), do: Phoenix.PubSub.subscribe(__MODULE__, "all") | ||
end |