Statifier.HistoryTracker (statifier v1.9.0)

View Source

Tracks history state configurations for SCXML state machines.

Implements W3C SCXML specification for shallow and deep history states. Records active state configurations before exiting parent states and provides retrieval for history state restoration.

Shallow vs Deep History

  • Shallow History: Records only immediate children of the parent state
  • Deep History: Records all atomic descendant states within the parent

W3C SCXML Compliance

History is recorded "before taking any transition that exits the parent" and restored when a transition targets a history state.

Summary

Functions

Clear all recorded history.

Clear history for a specific parent state.

Get the deep history for a parent state.

Get the shallow history for a parent state.

Check if a parent state has recorded history.

Create a new empty history tracker.

Record history for a parent state before it exits.

Types

history_entry()

@type history_entry() :: %{shallow: MapSet.t(String.t()), deep: MapSet.t(String.t())}

t()

@type t() :: %Statifier.HistoryTracker{
  history: %{required(String.t()) => history_entry()}
}

Functions

clear_all(tracker)

@spec clear_all(t()) :: t()

Clear all recorded history.

Resets the tracker to empty state, useful for testing or state machine restart.

clear_history(tracker, parent_state_id)

@spec clear_history(t(), String.t()) :: t()

Clear history for a specific parent state.

Useful for testing or when explicitly resetting history state.

get_deep_history(history_tracker, parent_state_id)

@spec get_deep_history(t(), String.t()) :: MapSet.t(String.t())

Get the deep history for a parent state.

Returns all atomic descendant states that were active when the parent was last exited. Returns empty set if no history has been recorded for this parent.

get_shallow_history(history_tracker, parent_state_id)

@spec get_shallow_history(t(), String.t()) :: MapSet.t(String.t())

Get the shallow history for a parent state.

Returns the immediate children that were active when the parent was last exited. Returns empty set if no history has been recorded for this parent.

has_history?(history_tracker, parent_state_id)

@spec has_history?(t(), String.t()) :: boolean()

Check if a parent state has recorded history.

Returns true if the parent state has been visited and exited before, false if this would be the first time entering the parent.

new()

@spec new() :: t()

Create a new empty history tracker.

record_history(tracker, parent_state_id, active_states, document)

@spec record_history(t(), String.t(), MapSet.t(String.t()), Statifier.Document.t()) ::
  t()

Record history for a parent state before it exits.

Records both shallow (immediate children) and deep (atomic descendants) history based on the current active state configuration.

Parameters

  • tracker - The history tracker
  • parent_state_id - ID of the parent state exiting
  • active_states - Current active state configuration
  • document - Document for state hierarchy analysis

Returns

Updated history tracker with recorded configuration.