SC.Actions.AssignAction (sc v1.0.2)

View Source

Represents an SCXML <assign> action for data model assignments.

The assign action assigns a value to a location in the data model. This enables dynamic data manipulation during state machine execution.

Attributes

  • location - The data model location to assign to (e.g., "user.name", "items[0]")
  • expr - The expression to evaluate and assign (e.g., "'John'", "count + 1")
  • source_location - Location in the source SCXML for error reporting

Examples

<assign location="user.name" expr="'John Doe'"/>
<assign location="counters.clicks" expr="counters.clicks + 1"/>
<assign location="settings['theme']" expr="'dark'"/>

SCXML Specification

From the W3C SCXML specification:

  • The assign element is used to modify the data model
  • The location attribute specifies the data model location
  • The expr attribute provides the value to assign
  • If location is not a valid left-hand-side expression, an error occurs

Summary

Functions

Execute the assign action by evaluating the expression and assigning to the location.

Create a new AssignAction from parsed attributes.

Types

t()

@type t() :: %SC.Actions.AssignAction{
  compiled_expr: term() | nil,
  expr: String.t(),
  location: String.t(),
  source_location: map() | nil
}

Functions

execute(assign_action, state_chart)

@spec execute(t(), SC.StateChart.t()) :: SC.StateChart.t()

Execute the assign action by evaluating the expression and assigning to the location.

This uses SC.ValueEvaluator to:

  1. Validate the assignment location path
  2. Evaluate the expression to get the value
  3. Perform the assignment in the data model

Returns the updated StateChart with modified data model.

new(location, expr, source_location \\ nil)

@spec new(String.t(), String.t(), map() | nil) :: t()

Create a new AssignAction from parsed attributes.

The expr is compiled for performance during creation.

Examples

iex> action = SC.Actions.AssignAction.new("user.name", "'John'")
iex> action.location
"user.name"
iex> action.expr
"'John'"
iex> is_list(action.compiled_expr) 
true