SC.Actions.AssignAction (sc v1.0.2)
View SourceRepresents 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
Functions
@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:
- Validate the assignment location path
- Evaluate the expression to get the value
- Perform the assignment in the data model
Returns the updated StateChart with modified data model.
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