Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Instance

Represents the active state configuration of a state machine instance.

remarks

This is the default implementation of the IInstance class and reads/writes to the active state configuration in a transactional manner at both initilisation and each call to evaluate.

Hierarchy

  • Instance

Implements

Index

Constructors

constructor

  • new Instance(name: string, root: State, activeStateConfiguration?: IState | undefined): Instance
  • Creates an instance of the Instance class.

    Parameters

    • name: string

      The name of the state machine instance.

    • root: State

      The root element of the state machine model that this an instance of.

    • Default value activeStateConfiguration: IState | undefined = undefined

      Optional JSON object used to initialise the active state configuration. The json object must have been produced by a prior call to Instance.toJSON from an instance using the same model.

    Returns Instance

Properties

name

name: string

The name of the state machine instance.

root

root: State

The root element of the state machine model that this an instance of.

Methods

defer

  • defer(state: State, trigger: any): void
  • Adds a trigger event to the event pool for later evaluation (once the state machine has changed state).

    Parameters

    • state: State
    • trigger: any

      The trigger event to defer.

    Returns void

deferrableTriggers

  • deferrableTriggers(state: State): Array<Constructor<any>>
  • Build a list of all the deferrable events at a particular state (including its children)

    Parameters

    • state: State

    Returns Array<Constructor<any>>

evaluate

  • evaluate(trigger: any): boolean
  • Passes a trigger event to the state machine instance for evaluation.

    Parameters

    • trigger: any

      The trigger event to evaluate.

    Returns boolean

    Returns true if the trigger event was consumed by the state machine (caused a transition or was deferred).

evaluateDeferred

  • evaluateDeferred(): void

getLastKnownState

  • getLastKnownState(region: Region): State | undefined
  • Returns the last known state of a given region. This is the call for application programmers to use as it returns the clean transactional state more efficently.

    Parameters

    • region: Region

      The region to get the last known state of.

    Returns State | undefined

    Returns the last known region of the given state. If the state has not been entered this will return undefined.

getState

  • getState(region: Region): State
  • Returns the last known state of a given region. This is the call for the state machine runtime to use as it returns the dirty transactional state.

    Parameters

    • region: Region

      The region to get the last known state of.

    Returns State

    Returns the last known region of the given state. If the state has not been entered this will return undefined.

getVertex

  • getVertex(region: Region): Vertex
  • Returns the last entered vertex to the state machine runtime.

    Parameters

    • region: Region

      The region to get the last entered vertex of.

    Returns Vertex

    Returns the last entered vertex for the given region.

regionFromJSON

  • regionFromJSON(region: Region, jsonRegion: IRegion): void
  • Reconstruct the active state configuration of a region from a json object.

    internal

    Parameters

    • region: Region

      The region to reconstruct.

    • jsonRegion: IRegion

      The json object holding a serialized version of the active state configuration.

    Returns void

regionToJSON

  • regionToJSON(region: Region): IRegion
  • Seriaize the active state configuration of a region to JSON.

    internal

    Parameters

    • region: Region

      The region to serialize.

    Returns IRegion

    Returns the JSON representation of the active state configuration of the region.

setState

  • setState(state: State): void
  • Updates the transactional state of a region with the last entered state.

    remarks

    This should only be called by the state machine runtime, and implementors note, you also need to update the last entered vertex within this call.

    Parameters

    • state: State

      The state set as its parents last entered state.

    Returns void

setVertex

  • setVertex(vertex: Vertex): void
  • Updates the transactional state of a region with the last entered vertex.

    remarks

    This should only be called by the state machine runtime.

    Parameters

    • vertex: Vertex

      The vertex set as its parents last entered vertex.

    Returns void

stateFromJSON

  • stateFromJSON(state: State, jsonState: IState): void
  • Reconstruct the active state configuration of a state from a json object.

    internal

    Parameters

    • state: State

      The state to reconstruct.

    • jsonState: IState

      The json object holding a serialized version of the active state configuration.

    Returns void

toJSON

  • toJSON(state?: State): IState
  • Serialize the active state configuration of the state machine instance to JSON.

    Parameters

    • Default value state: State = this.root

    Returns IState

    Returns the JSON representation of the active state configuration. This contains just the hierarchy of states and regions with the last known state of each region.

toString

  • toString(): string
  • Returns the name of the state machine instance.

    Returns string

    The name of the state machine instance.

transaction

  • transaction<TReturn>(operation: Producer<TReturn>): TReturn
  • Performs an operation within a transactional context.

    Type parameters

    • TReturn

      The type of the return parameter of the transactional operation.

    Parameters

    • operation: Producer<TReturn>

      The operation to perform within the transactional context.

    Returns TReturn

    Returns the return value from the transactional context.

Generated using TypeDoc