View Source Protean.Node (Protean v0.1.0)

Internal representation of an individual node in a Protean.MachineConfig struct.

Link to this section Summary

Types

An atomic node is a node without child states.

A complex Node is one that has child nodes.

A compound node is a node that defines children, of which only one can be active. It must additionally define an :initial attribute, the id of the child state that should default to active if the compound state is entered.

A final node is a type of atomic node that represents some form of completion, and can therefore define no transitions itself. Note, however, that activating a final node causes an event to be dispatched that a parent node can choose to handle.

ID encompasses the node and all its ancestors. For example, a node :child_a defined as a child of a node :parent_a might have the id [:child_a, :parent_a]

A leaf Node is one that cannot have child states.

A parallel node defines children, all of which are entered when the parallel node is entered.

A simple Node is one that cannot have child nodes.

t()

A Node is a node in a nested state machine. See the type docs for individual nodes for more details.

Functions

Given a Node id, return a list containing that id and all of its ancestors.

Tests whether descendant_id is in fact a descendant of ancestor_id. Returns false if they are the same node.

Return the entry actions associated with the node.

Sort the given nodes in entry order.

Return the exit actions associated with the node.

Sort the given nodes in exit order.

Given a Node id, return its parent's id. Returns nil if the Node is the root.

Resolve a Node to its leaves (atomic or final) by either returning the given node or following the node's children.

Link to this section Types

@type atomic() :: %Protean.Node{
  automatic_transitions: [Protean.Transition.t()],
  entry: [Protean.Action.t()],
  exit: [Protean.Action.t()],
  id: id(),
  initial: nil,
  order: non_neg_integer() | nil,
  states: nil,
  transitions: [Protean.Transition.t()],
  type: :atomic
}

An atomic node is a node without child states.

@type complex() :: compound() | parallel()

A complex Node is one that has child nodes.

@type compound() :: %Protean.Node{
  automatic_transitions: [Protean.Transition.t()],
  entry: [Protean.Action.t()],
  exit: [Protean.Action.t()],
  id: id(),
  initial: id(),
  order: non_neg_integer() | nil,
  states: [t(), ...],
  transitions: [Protean.Transition.t()],
  type: :compound
}

A compound node is a node that defines children, of which only one can be active. It must additionally define an :initial attribute, the id of the child state that should default to active if the compound state is entered.

@type final() :: %Protean.Node{
  automatic_transitions: [],
  entry: [Protean.Action.t()],
  exit: [Protean.Action.t()],
  id: id(),
  initial: nil,
  order: non_neg_integer() | nil,
  states: nil,
  transitions: [],
  type: :final
}

A final node is a type of atomic node that represents some form of completion, and can therefore define no transitions itself. Note, however, that activating a final node causes an event to be dispatched that a parent node can choose to handle.

@type id() :: [String.t(), ...]

ID encompasses the node and all its ancestors. For example, a node :child_a defined as a child of a node :parent_a might have the id [:child_a, :parent_a]

@type leaf() :: atomic() | final()

A leaf Node is one that cannot have child states.

@type nodes() :: [t()]
@type parallel() :: %Protean.Node{
  automatic_transitions: [Protean.Transition.t()],
  entry: [Protean.Action.t()],
  exit: [Protean.Action.t()],
  id: id(),
  initial: nil,
  order: non_neg_integer() | nil,
  states: [t(), ...],
  transitions: [Protean.Transition.t()],
  type: :parallel
}

A parallel node defines children, all of which are entered when the parallel node is entered.

@type simple() :: atomic() | final()

A simple Node is one that cannot have child nodes.

@type t() :: atomic() | final() | compound() | parallel()

A Node is a node in a nested state machine. See the type docs for individual nodes for more details.

Link to this section Functions

@spec ancestor_ids(id()) :: [id()]

Given a Node id, return a list containing that id and all of its ancestors.

Link to this function

common_ancestor_id(id1, id2)

View Source
@spec common_ancestor_id(id(), id()) :: id()
Link to this function

descendant?(descendant_id, ancestor_id)

View Source
@spec descendant?(id(), id()) :: boolean()

Tests whether descendant_id is in fact a descendant of ancestor_id. Returns false if they are the same node.

@spec entry_actions(t()) :: [Protean.Action.t()]

Return the entry actions associated with the node.

@spec entry_order(nodes()) :: nodes()

Sort the given nodes in entry order.

@spec exit_actions(t()) :: [Protean.Action.t()]

Return the exit actions associated with the node.

@spec exit_order(nodes()) :: nodes()

Sort the given nodes in exit order.

@spec parent_id(id()) :: id() | nil

Given a Node id, return its parent's id. Returns nil if the Node is the root.

@spec resolve_to_leaves(t()) :: [leaf()]

Resolve a Node to its leaves (atomic or final) by either returning the given node or following the node's children.