API Documentation for: 0.1.0
Show:

Blackboard Class

Defined in: Blackboard:35
Module: StateJS

The Blackboard is the memory structure required by machines and its states. It only have 2 public methods: set and get. These methods works in 3 different contexts: global, per machine, and per state per machine.

Suppose you have two different machines controlling a single object with a single blackboard, then:

  • In the global context, all states will access the stored information.
  • In per machine context, only states sharing the same machine share the stored information.
  • In per state per machine context, the information stored in the blackboard can only be accessed by the same state that wrote the data.

The context is selected indirectly by the parameters provided to these methods, for example:

// getting/setting variable in global context
blackboard.set('testKey', 'value');
var value = blackboard.get('testKey');

// getting/setting variable in per machine context
blackboard.set('testKey', 'value', machine.id);
var value = blackboard.get('testKey', machine.id);

// getting/setting variable in per state per machine context
blackboard.set('testKey', 'value', machine.id, state.id);
var value = blackboard.get('testKey', machine.id, state.id);

Note: Internally, the blackboard store these memories in different objects, being the global on _baseMemory, the per machine on _machineMemory and the per state per machine dynamically create inside the per machine memory (it is accessed via _machineMemory[id].stateMemory). Avoid to use these variables manually, use get and set instead.

Methods

_getMachineMemory

(
  • machineScope
)
Object protected

Internal method to retrieve the machine context memory. If the memory does not exist, this method creates it.

Parameters:

  • machineScope String

    The id of the machine in scope.

Returns:

Object:

The machine memory.

_getMemory

(
  • machineScope
  • stateScope
)
Object protected

Defined in _getMemory:125

Internal method to retrieve the context memory. If machineScope and stateScope are provided, this method returns the per state per machine memory. If only the machineScope is provided, it returns the per machine memory. If no parameter is provided, it returns the global memory. Notice that, if only stateScope is provided, this method will still return the global memory.

Parameters:

  • machineScope String

    The id of the machine scope.

  • stateScope String

    The id of the state scope.

Returns:

Object:

A memory object.

_getStateMemory

(
  • machineMemory
  • stateScope
)
Object protected

Defined in _getStateMemory:106

Internal method to retrieve the state context memory, given the machine memory. If the memory does not exist, this method creates is.

Parameters:

  • machineMemory String

    the machine memory.

  • stateScope String

    The id of the state in scope.

Returns:

Object:

The state memory.

get

(
  • key
  • machineScope
  • stateScope
)
Object

Defined in get:174

Retrieves a value in the blackboard. If machineScope and stateScope are provided, this method will retrieve the value from the per state per machine memory. If only the machineScope is provided, it will retrieve the value from the per machine memory. If no parameter is provided, this method will retrieve from the global memory. If only stateScope is provided (but machineScope not), this method will still try to retrieve from the global memory.

Parameters:

  • key String

    The key to be retrieved.

  • machineScope String

    The machine id if accessing the machine or state memory.

  • stateScope String

    The state id if accessing the state memory.

Returns:

Object:

The value stored or undefined.

initialize

()

Defined in initialize:77

Initialization method.

set

(
  • key
  • value
  • machineScope
  • stateScope
)

Defined in set:153

Stores a value in the blackboard. If machineScope and stateScope are provided, this method will save the value into the per state per machine memory. If only the machineScope is provided, it will save the value into the per machine memory. If no parameter is provided, this method will save the value into the global memory. Notice that, if only stateScope is provided (but machineScope not), this method will still save the value into the global memory.

Parameters:

  • key String

    The key to be stored.

  • value String

    The value to be stored.

  • machineScope String

    The machine id if accessing the machine or state memory.

  • stateScope String

    The state id if accessing the state memory.