AshDispatch.Resource.Transformers.InjectDispatchChanges (AshDispatch v0.5.0)

View Source

Transformer that registers AshDispatch.Notifier and persists per-action dispatch-event config for resources using the dispatch DSL block.

Pattern (post-tx-semantics retrofit)

Mirrors Ash.Notifier.PubSub.Info's shape: a single notifier (AshDispatch.Notifier) handles ALL resources' dispatch events; the per-action config is persisted into dsl_state and read at runtime by AshDispatch.Notifier.Info.dispatch_events_for/2.

Pre-retrofit, this transformer injected change AshDispatch.Changes.DispatchEvent per action — that change fired via Ash.Changeset.after_action/2 synchronously inside the action's transaction BEFORE commit/rollback, allowing phantom dispatches on rollback. Post-retrofit, work happens in Ash.Notifier's post-commit drain (or is dropped on error). See AshDispatch.Notifier moduledoc for the architectural justification.

Persisted state

  • :dispatch_channels%{event_id => [%Channel{}, ...]} (kept)
  • :ash_dispatch_dispatch_events — NEW; %{action_name => [event_config_map, ...]} for the notifier to consume per-action.
  • :simple_notifiers — adds AshDispatch.Notifier (mirrors InjectEntityNotifier's pattern).

Summary

Functions

after_compile?()

Callback implementation for Spark.Dsl.Transformer.after_compile?/0.

before?(_)

Callback implementation for Spark.Dsl.Transformer.before?/1.