PhoenixAssets.PubSub.Topics (PhoenixAssets v0.1.0)

View Source

DSL for declaring Phoenix PubSub topics and their event payloads.

A host module uses this and declares each topic's pattern and events:

defmodule MyApp.Assets.PubSubTopics do
  use PhoenixAssets.PubSub.Topics

  topic :device,
    pattern: "device:{id}",
    events: [updated: "Device", deleted: %{id: :string}]
end

An event payload is either a TypeScript type name (a string or module-like atom resolved against $phoenix/types) or an inline map of field to primitive type. Declarations are validated at compile time: a missing pattern:, an unknown option, or a malformed event payload is a compile error rather than a crash mid-generation.

use PhoenixAssets.PubSub.Topics

Using this module imports topic/2 and defines __phoenix_assets_topics__/0 with the validated declarations.

Summary

Functions

Declares a PubSub topic: pattern: and events:.

Functions

topic(name, opts)

(macro)

Declares a PubSub topic: pattern: and events:.