Ash.Signals.Graph (ash v3.36.1)

Copy Markdown View Source

Maps the signals of an application: the actions that emit each signal, and the listeners that react to it.

Used by mix ash.signals, which prints the map as text or as a Mermaid flowchart.

Summary

Functions

Returns an entry for each signal, with the actions that emit it and the listeners of it.

Renders entries from build/1 as a Mermaid flowchart.

Renders entries from build/1 as text, grouped by signal module, with the emitters and listeners of each signal grouped by resource, and the descriptions of signals, emits and listeners under them.

Types

emitter()

@type emitter() :: %{
  resource: Ash.Resource.t(),
  action: atom(),
  action_type: Ash.Resource.Actions.action_type(),
  emit: Ash.Resource.Actions.Emit.t()
}

entry()

@type entry() :: %{
  signal_module: Ash.Signals.t(),
  signal: Ash.Signals.Signal.t(),
  emitters: [emitter()],
  listeners: [Ash.Resource.SignalListener.t()]
}

Functions

build(opts \\ [])

@spec build(Keyword.t()) :: [entry()]

Returns an entry for each signal, with the actions that emit it and the listeners of it.

Listeners are found wherever they are defined, with Ash.Signals.Registry. Emitters are found in the given resources, and in the resources that listen to signals, since there is no registry of emitters.

Options

  • :resources - Resources to find emitters in. Defaults to [].
  • :signal_modules - Only map the signals of these signal modules. Defaults to every signal module, found with Ash.Signals.Registry.signal_modules/0, or emitted or listened to by the resources.

mermaid(entries)

@spec mermaid([entry()]) :: String.t()

Renders entries from build/1 as a Mermaid flowchart.

Each resource is a subgraph of the actions that emit or listen to signals, and each signal module is a subgraph of its signals. Listeners with a delivery other than Ash.Signals.Delivery.Inline are dotted lines, labelled with their delivery.

text(entries)

@spec text([entry()]) :: String.t()

Renders entries from build/1 as text, grouped by signal module, with the emitters and listeners of each signal grouped by resource, and the descriptions of signals, emits and listeners under them.