PhoenixReplay.Replay behaviour (PhoenixReplay v0.6.2)

Copy Markdown View Source

How your app's recordings are replayed, as a whole. For how one LiveView renders in a replay, see PhoenixReplay.Replay.View; for assigns that changed shape since a recording, see PhoenixReplay.Migration.

Replays render today's templates and root layout with the assigns recorded then, and most need nothing more: an assign a recording lacks is rendered as nil, and the root layout, rendered again at each moment, gives the replayed page's <html> and <body> their attributes, such as a theme. A module of this behaviour, configured as :replay, covers a layout whose attributes come from something other than its assigns:

config :phoenix_replay, replay: MyAppWeb.Replay

defmodule MyAppWeb.Replay do
  @behaviour PhoenixReplay.Replay

  @impl true
  def root_attributes(_view, assigns), do: %{"data-plan" => assigns[:plan]}
end

Its callback is optional.

Summary

Callbacks

Attributes for the replayed page's <html> at a moment, besides those the root layout renders, for a layout whose attributes come from something other than its assigns.

Functions

Calls module's root_attributes/2, with names and values as strings, or returns no attributes without it.

Callbacks

root_attributes(view, assigns)

(optional)
@callback root_attributes(view :: module(), assigns :: map()) :: %{
  optional(String.t() | atom()) => String.t() | nil
}

Attributes for the replayed page's <html> at a moment, besides those the root layout renders, for a layout whose attributes come from something other than its assigns.

Functions

root_attributes(module, view, assigns)

@spec root_attributes(module() | nil, module(), map()) :: %{
  required(String.t()) => String.t() | nil
}

Calls module's root_attributes/2, with names and values as strings, or returns no attributes without it.