Raxol.Debug.TimeTravel
(Raxol v2.3.0)
View Source
Time-travel debugger for TEA applications.
Records a snapshot of the application model at every update/2 cycle.
Supports stepping forward and backward through state history, inspecting
diffs between any two points, and restoring the live application to a
historical state.
Usage
Enable via Lifecycle options:
Raxol.start_link(MyApp, time_travel: true)
Raxol.start_link(MyApp, time_travel: [max_snapshots: 2000])Or start standalone and attach to a running Dispatcher:
{:ok, pid} = TimeTravel.start_link(dispatcher: dispatcher_pid)Then navigate:
TimeTravel.step_back() # -> {:ok, %Snapshot{}}
TimeTravel.step_forward() # -> {:ok, %Snapshot{}}
TimeTravel.current() # -> {:ok, %Snapshot{}}
TimeTravel.jump_to(42) # -> {:ok, %Snapshot{}}
TimeTravel.restore() # re-render the model at the cursor position
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears all recorded snapshots.
Returns the total number of recorded snapshots.
Returns the snapshot at the current cursor position.
Diffs two snapshots by index. Returns change list.
Exports snapshots to a file (Erlang term format).
Imports snapshots from a file.
Jumps the cursor to a specific snapshot index.
Returns a list of snapshot summaries.
Pauses snapshot recording.
Records a snapshot. Called by the Dispatcher after each update/2.
Restores the live application model to the snapshot at the current cursor.
Resumes recording after a restore (recording pauses automatically on restore).
Starts the time-travel debugger.
Steps the cursor back one snapshot.
Steps the cursor forward one snapshot.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Clears all recorded snapshots.
@spec count(pid() | atom()) :: non_neg_integer()
Returns the total number of recorded snapshots.
@spec current(pid() | atom()) :: {:ok, Raxol.Debug.Snapshot.t()} | {:error, :empty}
Returns the snapshot at the current cursor position.
@spec diff(pid() | atom(), non_neg_integer(), non_neg_integer()) :: {:ok, [Raxol.Debug.Snapshot.change()]} | {:error, :not_found}
Diffs two snapshots by index. Returns change list.
Exports snapshots to a file (Erlang term format).
@spec import_file(pid() | atom(), Path.t()) :: {:ok, non_neg_integer()} | {:error, term()}
Imports snapshots from a file.
@spec jump_to(pid() | atom(), non_neg_integer()) :: {:ok, Raxol.Debug.Snapshot.t()} | {:error, :not_found}
Jumps the cursor to a specific snapshot index.
Returns a list of snapshot summaries.
Pauses snapshot recording.
Records a snapshot. Called by the Dispatcher after each update/2.
Restores the live application model to the snapshot at the current cursor.
Sends {:restore_model, model} to the Dispatcher, which updates its state
and triggers a re-render. Automatically pauses recording so the restore
itself doesn't get recorded as a new snapshot.
Resumes recording after a restore (recording pauses automatically on restore).
@spec start_link(keyword()) :: GenServer.on_start()
Starts the time-travel debugger.
@spec step_back(pid() | atom()) :: {:ok, Raxol.Debug.Snapshot.t()} | {:error, :at_start}
Steps the cursor back one snapshot.
@spec step_forward(pid() | atom()) :: {:ok, Raxol.Debug.Snapshot.t()} | {:error, :at_end}
Steps the cursor forward one snapshot.