Raxol.Debug.Snapshot (Raxol v2.3.0)

View Source

A single point-in-time capture of a TEA update cycle.

Stores the message that triggered the update, the model before and after, and a monotonic timestamp for ordering. Provides a recursive map diff utility for inspecting what changed between any two models.

Summary

Functions

Returns true if the model changed in this snapshot.

Computes the diff between two models (or two snapshots).

Returns a compact summary string for a snapshot.

Types

change()

@type change() ::
  {:changed, [term()], old :: term(), new :: term()}
  | {:added, [term()], term()}
  | {:removed, [term()], term()}

t()

@type t() :: %Raxol.Debug.Snapshot{
  index: non_neg_integer(),
  message: term(),
  model_after: map(),
  model_before: map(),
  timestamp_us: integer()
}

Functions

changed?(snapshot)

@spec changed?(t()) :: boolean()

Returns true if the model changed in this snapshot.

diff(snap, model)

@spec diff(map() | t(), map() | t()) :: [change()]

Computes the diff between two models (or two snapshots).

Returns a list of {:changed, path, old, new}, {:added, path, val}, and {:removed, path, val} tuples where path is a list of map keys.

iex> Snapshot.diff(%{a: 1, b: 2}, %{a: 1, b: 3, c: 4})
[{:changed, [:b], 2, 3}, {:added, [:c], 4}]

new(index, message, model_before, model_after)

@spec new(non_neg_integer(), term(), map(), map()) :: t()

Creates a new snapshot.

summary(snap)

@spec summary(t()) :: String.t()

Returns a compact summary string for a snapshot.